Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2003, 11:32 AM
aac aac is offline
Authorized User
 
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update Problem

I'm atemping to create a page that will update my database, the page runs and executes everything but the actual database is not updated, is there another line of code i need in order to do this, thanks

<%@ Page Language="c#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    OleDbConnection objConnection;
    private void Page_Load(object sender, System.EventArgs e)
    {
    objConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=AAC.mdb");
    }

    private void btnInsert_Click(object sender, System.EventArgs e)
    {
    if (Page.IsValid)
    {
    String strSQL = "INSERT INTO Hardware (Type, Location, Manufacturer, ModelNumber, SerialNumber, Other) VALUES (?, ?, ?, ?, ?, ?)";
    OleDbCommand dbComm = new OleDbCommand(strSQL, objConnection);
    dbComm.Parameters.Add("Type", OleDbType.VarChar, 32, "Type");
    dbComm.Parameters.Add("Location", OleDbType.VarChar, 32, "Location");
    dbComm.Parameters.Add("Manufacturer", OleDbType.VarChar, 32, "Manufacturer");
    dbComm.Parameters.Add("ModelNumber", OleDbType.VarChar, 32, "ModelNumber");
    dbComm.Parameters.Add("SerialNumber", OleDbType.VarChar, 32, "SerialNumber");
    dbComm.Parameters.Add("Other", OleDbType.VarChar, 32, "Other");
    dbComm.Parameters["Type"].Value = txtType.Text;
    dbComm.Parameters["Location"].Value = txtLocation.Text;
    dbComm.Parameters["Manufacturer"].Value = txtManufacturer.Text;
    dbComm.Parameters["ModelNumber"].Value = txtModelNumber.Text;
    dbComm.Parameters["SerialNumber"].Value = txtSerialNumber.Text;
    dbComm.Parameters["Other"].Value = txtOther.Text;
    try
    {
    objConnection.Open();
    dbComm.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    Response.End();
    }
    finally
    {
    if (objConnection.State == ConnectionState.Open);
    objConnection.Close();
    }
    Response.Write("A new record has been added");
    Response.End();
    }
    }

</script>
<html>
<head>
    <title>Adding a New Record</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <table id="Table1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" cellspacing="0" cellpadding="0" width="300" border="0">
            <tbody>
                <tr>
                    <td style="WIDTH: 115px">
                        <asp:Label id="Label1" runat="server">Type</asp:Label></td>
                    <td>
                        <asp:TextBox id="txtType" runat="server" width="193"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 115px">
                        <asp:Label id="Label2" runat="server">Location</asp:Label></td>
                    <td>
                        <asp:TextBox id="txtLocation" runat="server" width="193"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 115px">
                        <asp:Label id="Label3" runat="server">Manufacturer</asp:Label></td>
                    <td>
                        <asp:TextBox id="txtManufacturer" runat="server" width="193"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 115px">
                        <asp:Label id="Label4" runat="server">ModelNumber</asp:Label></td>
                    <td>
                        <asp:TextBox id="txtModelNumber" runat="server" width="193"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 115px">
                        <asp:Label id="Label5" runat="server">SerialNumber</asp:Label></td>
                    <td>
                        <asp:TextBox id="txtSerialNumber" runat="server" width="193"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 115px">
                        <asp:Label id="Label6" runat="server">Other</asp:Label></td>
                    <td>
                        <asp:TextBox id="txtOther" runat="server" width="193"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button id="btnInsert" onclick="btnInsert_Click" runat="server" width="298" text="INSERT"></asp:Button>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>


 
Old July 21st, 2003, 02:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The code below looks like an INSERT statement and not an update statement. Are you sure you posted the right code, or do you mean "inserting a record" by "updating the database"?

Secondly, the reference to you database is not OK. It needs a full physical path to the database, and not a relative / virtual path like yours. Try this instead:

Provider=Microsoft.Jet.OLEDB.4.0; data source=C:\inetpub\wwwroot\MySite\Database\AAC.mdb

Thirdly, this is a (classic) ASP forum. You may try your luck in one of the ASP.NET or ADO.NET list that are available here......

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old July 21st, 2003, 03:34 PM
aac aac is offline
Authorized User
 
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your help, i do mean insert not update, the path you gave me didnt work though, i will try looking for help in the other forum, thanks for that tip






Similar Threads
Thread Thread Starter Forum Replies Last Post
Update problem aceaceace Visual Basic 2005 Basics 6 February 21st, 2007 10:25 PM
Update problem filipczako ADO.NET 6 December 15th, 2005 11:58 AM
Update Problem skwilliams Classic ASP Databases 0 December 1st, 2005 11:02 AM
Update problem acko SQL Server 2000 3 June 29th, 2004 01:50 AM
update problem Justine Classic ASP Databases 21 May 26th, 2004 04:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.