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>
|