here's the code
<%@ Page Language="c#" Debug="True" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
OleDbConnection objConnection;
private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection objConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=AAC.mbd");
}
private void btnInsert_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
String strSQL = "INSERT INTO Computers (Location, User, TypeOfComputer, Manufacturer, ModelNumber, SerialNumber, DatePurchased, DateGarunteed, DateMaintenence, CPU, Memory, HardDrive, CDROM, SoundCard, VideoCard, NetworkID, PrinterType, OtherEquipment, OS, ApplicationSoftware, NetworkCard, NetworkConnection, Update) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
OleDbCommand dbComm = new OleDbCommand(strSQL, objConnection);
dbComm.Parameters.Add("Location", OleDbType.VarChar, 32, "Location");
dbComm.Parameters.Add("User", OleDbType.VarChar, 32, "User");
dbComm.Parameters.Add("TypeOfComputer", OleDbType.VarChar, 32, "TypeOfComputer");
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("DatePurchased", OleDbType.VarChar, 32, "DatePurchased");
dbComm.Parameters.Add("DateGarunteed", OleDbType.VarChar, 32, "DateGarunteed");
dbComm.Parameters.Add("DateMaintenence", OleDbType.VarChar, 32, "DateMaintenence");
dbComm.Parameters.Add("CPU", OleDbType.VarChar, 32, "CPU");
dbComm.Parameters.Add("Memory", OleDbType.VarChar, 32, "Memory");
dbComm.Parameters.Add("HardDrive", OleDbType.VarChar, 32, "HardDrive");
dbComm.Parameters.Add("CDROM", OleDbType.VarChar, 32, "CDROM");
dbComm.Parameters.Add("SoundCard", OleDbType.VarChar, 32, "SoundCard");
dbComm.Parameters.Add("VideoCard", OleDbType.VarChar, 32, "VideoCard");
dbComm.Parameters.Add("NetworkID", OleDbType.VarChar, 32, "NetworkID");
dbComm.Parameters.Add("PrinterType", OleDbType.VarChar, 32, "PrinterType");
dbComm.Parameters.Add("OtherEquipment", OleDbType.VarChar, 32, "OtherEquipment");
dbComm.Parameters.Add("OS", OleDbType.VarChar, 32, "OS");
dbComm.Parameters.Add("ApplicationSoftware", OleDbType.VarChar, 32, "ApplicationSoftware");
dbComm.Parameters.Add("NetworkCard", OleDbType.VarChar, 32, "NetworkCard");
dbComm.Parameters.Add("NetworkConnection", OleDbType.VarChar, 32, "NetworkConnection");
dbComm.Parameters.Add("Update", OleDbType.VarChar, 32, "Update");
dbComm.Parameters["Location"].Value = txtLocation.Text;
dbComm.Parameters["User"].Value = txtUser.Text;
dbComm.Parameters["TypeOfComputer"].Value = txtTypeOfComputer.Text;
dbComm.Parameters["Manufacturer"].Value = txtManufacturer.Text;
dbComm.Parameters["ModelNumber"].Value = txtModelNumber.Text;
dbComm.Parameters["SerialNumber"].Value = txtSerialNumber.Text;
dbComm.Parameters["DatePurchased"].Value = txtDatePurchased.Text;
dbComm.Parameters["DateGarunteed"].Value = txtDateGarunteed.Text;
dbComm.Parameters["DateMaintenence"].Value = txtDateMaintenence.Text;
dbComm.Parameters["CPU"].Value = txtCPU.Text;
dbComm.Parameters["Memory"].Value = txtMemory.Text;
dbComm.Parameters["HardDrive"].Value = txtHardDrive.Text;
dbComm.Parameters["CDROM"].Value = txtCDROM.Text;
dbComm.Parameters["SoundCard"].Value = txtSoundCard.Text;
dbComm.Parameters["VideoCard"].Value = txtVideoCard.Text;
dbComm.Parameters["NetworkID"].Value = txtNetworkID.Text;
dbComm.Parameters["PrinterType"].Value = txtPrinterType.Text;
dbComm.Parameters["OtherEquipment"].Value = txtOtherEquipment.Text;
dbComm.Parameters["OS"].Value = txtOS.Text;
dbComm.Parameters["ApplicationSoftware"].Value = txtApplicationSoftware.Text;
dbComm.Parameters["NetworkCard"].Value = txtNetworkCard.Text;
dbComm.Parameters["NetworkConnection"].Value = txtNetworkConnection.Text;
dbComm.Parameters["Update"].Value = txtUpdate.Text;
int iID = 0;
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>Validating a Feild</title>
</head>
<body>
<form id="Form1" methode="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">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="Label2" runat="server">User</asp:Label></td>
<td>
<asp:TextBox id="txtUser" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label3" runat="server">Type of Computer</asp:Label></td>
<td>
<asp:TextBox id="txtTypeOfComputer" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label4" 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="Label5" runat="server">Model Number</asp:Label></td>
<td>
<asp:TextBox id="txtModelNumber" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label6" runat="server">Serial Number</asp:Label></td>
<td>
<asp:TextBox id="txtSerialNumber" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label7" runat="server">Date Purchased</asp:Label></td>
<td>
<asp:TextBox id="txtDatePurchased" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label8" runat="server">Date Garuntee Expires</asp:Label></td>
<td>
<asp:TextBox id="txtDateGarunteed" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label9" runat="server">Date Maintenence Contract Renewal</asp:Label></td>
<td>
<asp:TextBox id="txtDateMaintenence" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label10" runat="server">CPU</asp:Label></td>
<td>
<asp:TextBox id="txtCPU" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label11" runat="server">Memory</asp:Label></td>
<td>
<asp:TextBox id="txtMemory" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label12" runat="server">HardDrive</asp:Label></td>
<td>
<asp:TextBox id="txtHardDrive" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label13" runat="server">CD-ROM</asp:Label></td>
<td>
<asp:TextBox id="txtCDROM" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label14" runat="server">SoundCard</asp:Label></td>
<td>
<asp:TextBox id="txtSoundCard" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label15" runat="server">VideoCard</asp:Label></td>
<td>
<asp:TextBox id="txtVideoCard" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label16" runat="server">NetworkID</asp:Label></td>
<td>
<asp:TextBox id="txtNetworkID" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label17" runat="server">Printer Type</asp:Label></td>
<td>
<asp:TextBox id="txtPrinterType" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label18" runat="server">Other Equipment</asp:Label></td>
<td>
<asp:TextBox id="txtOtherEquipment" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label19" runat="server">OS</asp:Label></td>
<td>
<asp:TextBox id="txtOS" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label20" runat="server">Application Software</asp:Label></td>
<td>
<asp:TextBox id="txtApplicationSoftware" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label21" runat="server">Network Card</asp:Label></td>
<td>
<asp:TextBox id="txtNetworkCard" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label22" runat="server">Network Connection</asp:Label></td>
<td>
<asp:TextBox id="txtNetworkConnection" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px">
<asp:Label id="Label23" runat="server">Update</asp:Label></td>
<td>
<asp:TextBox id="txtUpdate" runat="server" width="193"></asp:TextBox>
</td>
</tr>
<tr>
<td style="WIDTH: 115px" colspan="2">
<asp:Button id="btnInsert" onclick="btnInsert_Click" runat="server" width="298px" Height="27px" text="INSERT!"></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
|