Hello. As the subject heading says, I'm not able to insert data typed into the contact form on my page into a database table. I'm using an SqlDataSource object. Here's the code for this page:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@. Page Language="VB" Debug="True" Explicit="True" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.Odbc" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<div align="center">
<asp:label ID="label1" runat="server" Font-Name="Arial" Font-Size="24" ForeColor="#00FF00" />
</div>
<div align="center">
<asp:label ID="label2" runat="server" Font-Name="Verdana" Font-Size="18" ForeColor="#0000FF" />
</div>
<form runat="server" id="new_form">
<table width="50%" border="1" align="center" id="form_table">
<tr>
<td nowrap="nowrap">
<asp:label Font-Bold="true" Font-Size="10" runat="server" Font-Name="CarlysHand" Text="First Name" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("FirstName") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="15" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="first" TabIndex="1" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="first" Type="String" ErrorMessage="Please enter your first name." Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Middle Initial" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("MI") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="1" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="mi" TabIndex="2" /></td>
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Last Name" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("LastName") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="18" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="last" TabIndex="3" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="last" Type="String" ErrorMessage="Please enter your last name." Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Number & Street" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("NoAndStreet") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="40" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="no_and_street" TabIndex="4" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="no_and_street" Type="String" ErrorMessage="Please enter your number and street." Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Unit #" BackColor="#FFE1E1" ForeColor="#FF0000" />
</td>
<td><asp:textbox text='<%#Bind("Unit") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="6" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="unit" TabIndex="5" /></td>
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="City" BackColor="#FFE1E1" ForeColor="#FF0000" />
</td>
<td><asp:textbox text='<%#Bind("City") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="20" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="city" TabIndex="6" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="city" Type="String" ErrorMessage="Please enter your city." Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="State" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("State") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="2" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="state" TabIndex="7" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="state" ErrorMessage="Please enter your state." Type="String" Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Zip Code" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("ZipCode") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="5" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="zip" TabIndex="8" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="zip" ErrorMessage="Please enter your zip code." Type="Integer" Display="Dynamic" />
<asp:regularexpressionvalidator Display="Dynamic" runat="server" ValidationExpression="[0123456789]{5}" ControlToValidate="zip" ErrorMessage="Please enter a valid US Zip Code" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Phone #" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("PhoneNumber") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="10" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="phone" TabIndex="9" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="phone" ErrorMessage="Please enter your phone number." Type="Double" Display="Dynamic" />
<asp:rangevalidator runat="server" ControlToValidate="phone" MinimumValue="2002000000" MaximumValue="9999999999" Type="Double" ErrorMessage="Please enter a valid US Phone Number." Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Email" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("Email") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="40" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="email" TabIndex="10" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="email" ErrorMessage="Please enter your email address." Type="String" Display="Dynamic" />
<asp:regularexpressionvalidator runat="server" ControlToValidate="email" ErrorMessage="Please enter a valid email address." ValidationExpression=".*@..{2,}\..{2,}" Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Username" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox text='<%#Bind("Username") %>' BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="12" TextMode="SingleLine" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="username" TabIndex="11" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="username" ErrorMessage="Please enter your username." Type="String" Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Password" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td> <asp:textbox text='<%#Bind("Password") %>' Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="12" TextMode="Password" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="password" TabIndex="12" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="password" ErrorMessage="Please enter your password." Type="String" Display="Dynamic" />
</tr>
<tr>
<td nowrap="nowrap">
<asp:label Font-Size="10" Font-Bold="true" runat="server" Font-Name="CarlysHand" Text="Confirm Password" BackColor="#FFE1E1" ForeColor="#FF0000" /></td>
<td><asp:textbox Font-Size="10" BorderColor="#BF0000" BorderStyle="Groove" BorderWidth="2" BackColor="#FFCCFF" ForeColor="#FF0000" Columns="12" TextMode="Password" Font-Bold="true" Font-Name="CarlysHand" runat="server" ID="confirm" TabIndex="13" /></td>
<asp:requiredfieldvalidator runat="server" ControlToValidate="confirm" ErrorMessage="Please confirm your password." Type="String" Display="Dynamic" />
<asp:comparevalidator runat="server" ControlToValidate="confirm" ControlToCompare="password" Type="String" ErrorMessage="Please input matching passwords." Display="Dynamic" />
</tr>
<tr>
<td colspan="2" align="center" nowrap="nowrap"><asp:linkbutton BorderColor="#0000FF" BorderWidth="3" BorderStyle="Dotted" ToolTip="Click me!" Text="Submit" Font-Name="CarlysHand" Font-Size="15" Font-Bold="true" BackColor="#CCCCCC" ForeColor="#FF0000" runat="server" ID="submit" TabIndex="14" /></td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="driver={MySQL ODBC 3.51 Driver};server=mysql01.discountasp.net;
data source=bkfwebdesi1_mysqlConn;database=MYSQLDB_316823;uid=bkfwebdesi1;
password=bkf2065"
ProviderName="System.Data.Odbc"
InsertCommand="INSERT INTO ContactInfo VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?)">
<InsertParameters>
<asp:Parameter Name="ContactID" Type="Int32" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="MI" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="NoAndStreet" Type="String" />
<asp:Parameter Name="Unit" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="ZipCode" Type="Int32" />
<asp:Parameter Name="PhoneNumber" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Password" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
Thanks in advance for your help in this matter!
Brian
You need to put your contact form inside a databound control - such as a FormView. Then you need to associate the FormView with your datasource. At the moment, your fields have no connection with the SqlDataSource.
The other problem is that the SqlDataSource will ONLY work with an SQL Server database. Download a free version of SQL Server Express, or if you HAVE to use MySQL (yuk), you need to use another way of passing commands to the datasource. I don't know which one, but probably the ODBC provider for .NET <me shudders>.
No comments:
Post a Comment