Code Cleric
Perch
Hi. First off I am new to .NET... I have a MS Access database with one table, called "client_profile" that table has the following fields... "profile_ID" = autonumber the rest are text... "Company_Name", "Contact_Name", "Address", "City", "State", "Zip", "Phone", "Phone_2", "Fax", "Email"....I am using a simple form to accept user input for all fields except the autonumber ID. The page is producing no errors, however is not inserting the new record... If anyone can help to explain to me what I have done wrong, I would be eternally grateful. The following is the source...
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<script language="vb" runat="server">
Dim myConnection as OleDbConnection
Dim strConnectionString as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mwt.mdb")
Sub Page_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
GetConnection()
End If
End Sub
Sub AddNewClient(ByVal sender As System.Object, ByVal e As System.EventArgs)
GetConnection()
Dim strSQL as String = "INSERT INTO client_profile(Company_Name,Contact_Name,Address,City,State,Zip,Phone,Phone_2,Fax,Email) values('" & _
clientname.Text & "','" & _
clientcontact.Text & "','" & _
clientaddress.Text & "','" & _
clientcity.Text & "','" & _
clientstate.Text & "','" & _
clientzip.Text & "','" & _
clientphone.Text & "','"& _
clientphone2.Text & "','"& _
clientfax.Text & "','"& _
clientemail.Text & "')'"
Dim myCommand as New OleDbCommand(strSQL, myConnection)
ClearForm()
End Sub
Sub GetConnection()
myConnection = New OleDbConnection(strConnectionString)
myConnection.Open
End Sub
Sub ClearForm()
clientname.Text = ""
clientcontact.Text = ""
clientaddress.Text = ""
clientcity.Text = ""
clientstate.Text = ""
clientzip.Text = ""
clientphone.Text = ""
clientphone2.Text = ""
clientfax.Text = ""
clientemail.Text = ""
End Sub
</script>
<head>
<title>New Client Entry Sheet</title>
<link href="clientinfo.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#DBDBDB">
<form method="post" runat="server">
<table align="center" width="575" border="0">
<tr>
<td align="center" colspan="3">
<h1>New Client Entry Form</h1><br><br><br>
</td>
</tr>
<tr>
<td class="input_caption">Company Name: </td>
<td>
<asp:TextBox ID="clientname" CssClass="textbox" ToolTip="Enter Company Name for this Client" Columns="50" MaxLength="50" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Contact Name: </td>
<td>
<asp:TextBox ID="clientcontact" CssClass="textbox" ToolTip="Enter Contact Name for this Client" Columns="50" MaxLength="25" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Address: </td>
<td>
<asp:TextBox ID="clientaddress" CssClass="textbox" ToolTip="Enter the Address for this Client" Columns="50" MaxLength="25" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">City: </td>
<td>
<asp:TextBox ID="clientcity" CssClass="textbox" ToolTip="Enter the City for this Client" Columns="50" MaxLength="25" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">State: </td>
<td class="input_zip">
<nobr><asp:TextBox ID="clientstate" CssClass="textbox" ToolTip="Enter the State for this Client" Columns="20" MaxLength="15" runat="server" />
Zip: <asp:TextBox ID="clientzip" CssClass="textbox" ToolTip="Enter the Zip for this Client" Columns="18" MaxLength="5" runat="server" /></nobr>
</td>
</tr>
<tr>
<td class="input_caption">Phone: </td>
<td>
<asp:TextBox ID="clientphone" CssClass="textbox" ToolTip="Enter the Phone for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Phone 2: </td>
<td>
<asp:TextBox ID="clientphone2" CssClass="textbox" ToolTip="Enter the Secondary Phone for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Fax: </td>
<td>
<asp:TextBox ID="clientfax" CssClass="textbox" ToolTip="Enter the Fax for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Email: </td>
<td>
<asp:TextBox ID="clientemail" CssClass="textbox" ToolTip="Enter the Email for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="addclient" OnClick="AddNewClient" runat="server" Text="Add Client" />
<input align="right" type="reset" value="Clear Form">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<script language="vb" runat="server">
Dim myConnection as OleDbConnection
Dim strConnectionString as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mwt.mdb")
Sub Page_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
GetConnection()
End If
End Sub
Sub AddNewClient(ByVal sender As System.Object, ByVal e As System.EventArgs)
GetConnection()
Dim strSQL as String = "INSERT INTO client_profile(Company_Name,Contact_Name,Address,City,State,Zip,Phone,Phone_2,Fax,Email) values('" & _
clientname.Text & "','" & _
clientcontact.Text & "','" & _
clientaddress.Text & "','" & _
clientcity.Text & "','" & _
clientstate.Text & "','" & _
clientzip.Text & "','" & _
clientphone.Text & "','"& _
clientphone2.Text & "','"& _
clientfax.Text & "','"& _
clientemail.Text & "')'"
Dim myCommand as New OleDbCommand(strSQL, myConnection)
ClearForm()
End Sub
Sub GetConnection()
myConnection = New OleDbConnection(strConnectionString)
myConnection.Open
End Sub
Sub ClearForm()
clientname.Text = ""
clientcontact.Text = ""
clientaddress.Text = ""
clientcity.Text = ""
clientstate.Text = ""
clientzip.Text = ""
clientphone.Text = ""
clientphone2.Text = ""
clientfax.Text = ""
clientemail.Text = ""
End Sub
</script>
<head>
<title>New Client Entry Sheet</title>
<link href="clientinfo.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#DBDBDB">
<form method="post" runat="server">
<table align="center" width="575" border="0">
<tr>
<td align="center" colspan="3">
<h1>New Client Entry Form</h1><br><br><br>
</td>
</tr>
<tr>
<td class="input_caption">Company Name: </td>
<td>
<asp:TextBox ID="clientname" CssClass="textbox" ToolTip="Enter Company Name for this Client" Columns="50" MaxLength="50" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Contact Name: </td>
<td>
<asp:TextBox ID="clientcontact" CssClass="textbox" ToolTip="Enter Contact Name for this Client" Columns="50" MaxLength="25" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Address: </td>
<td>
<asp:TextBox ID="clientaddress" CssClass="textbox" ToolTip="Enter the Address for this Client" Columns="50" MaxLength="25" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">City: </td>
<td>
<asp:TextBox ID="clientcity" CssClass="textbox" ToolTip="Enter the City for this Client" Columns="50" MaxLength="25" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">State: </td>
<td class="input_zip">
<nobr><asp:TextBox ID="clientstate" CssClass="textbox" ToolTip="Enter the State for this Client" Columns="20" MaxLength="15" runat="server" />
Zip: <asp:TextBox ID="clientzip" CssClass="textbox" ToolTip="Enter the Zip for this Client" Columns="18" MaxLength="5" runat="server" /></nobr>
</td>
</tr>
<tr>
<td class="input_caption">Phone: </td>
<td>
<asp:TextBox ID="clientphone" CssClass="textbox" ToolTip="Enter the Phone for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Phone 2: </td>
<td>
<asp:TextBox ID="clientphone2" CssClass="textbox" ToolTip="Enter the Secondary Phone for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Fax: </td>
<td>
<asp:TextBox ID="clientfax" CssClass="textbox" ToolTip="Enter the Fax for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td class="input_caption">Email: </td>
<td>
<asp:TextBox ID="clientemail" CssClass="textbox" ToolTip="Enter the Email for this Client" Columns="50" MaxLength="12" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="addclient" OnClick="AddNewClient" runat="server" Text="Add Client" />
<input align="right" type="reset" value="Clear Form">
</td>
</tr>
</table>
</form>
</body>
</html>