FormView Control in ASP.NET 2.0 beta2 with MySQL

  • Thread starter Thread starter pete
  • Start date Start date
P

pete

I seem unable to get the FormView with the SqlDataSource control in ASP.NET
2.0 beta 2 to insert into my MySQL 4.11 database corectly. When I run the
page and click on the Insert link a SQL insert happens and a record gets
inserted into my MySQL table but every field that is inserted is NULL.

I have a feeling it I am referancing the values incorrectly with my
InsertCommand. Here is the insert command:

InsertCommand="insert into guestbook (firstname,lastname,city) values
(@firstname,@lastname,@city)

Any help pn this would be very much appreciated,
Pete


Here is my table defination:

CREATE TABLE `guestbook` ( `autoid` int(10) unsigned NOT NULL
auto_increment, `firstname` varchar(30) default NULL, `lastname` varchar(30)
default NULL, `emailaddress` varchar(60) default NULL, `city` varchar(30)
default NULL, `prov` varchar(30) default NULL, `country` varchar(30) default
NULL, `comments` text, `ipaddress` varchar(20) default NULL, `addtime`
datetime default '0000-00-00 00:00:00', PRIMARY KEY (`autoid`), UNIQUE KEY
`autoid` (`autoid`), KEY `autoid_2` (`autoid`))

Below is my code:
<%@ Page Language="VB" CodeFile="newentry.aspx.vb" Inherits="newentry" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server"
DataSourceID="SqlDataSource1" DefaultMode="Insert" DataKeyNames="autoid"
DataMember="defaultview">
<InsertItemTemplate>
<table>
<tr><td>firstname:</td><td>
<asp:TextBox ID="firstnameTextBox" runat="server"
Text='<%# Bind("firstname") %>'>
</asp:TextBox></td></tr>
<tr><td>lastname:</td><td>
<asp:TextBox ID="lastnameTextBox" runat="server"
Text='<%# Bind("lastname") %>'>
</asp:TextBox></td></tr>
<tr><td>emailaddress:</td><td>
<asp:TextBox ID="emailaddressTextBox" runat="server"
Text='<%# Bind("emailaddress") %>'>
</asp:TextBox></td></tr>

<tr><td>country:</td><td>
<asp:TextBox ID="countryTextBox" runat="server"
Text='<%# Bind("country") %>'>
</asp:TextBox></td></tr>
<tr><td>prov:</td><td>
<asp:TextBox ID="provTextBox" runat="server" Text='<%#
Bind("prov") %>'>
</asp:TextBox></td></tr>
<tr><td>city:</td><td>
<asp:TextBox ID="cityTextBox" runat="server" Text='<%#
Bind("city") %>'>
</asp:TextBox></td></tr>
<tr><td>comments:</td><td>
<asp:TextBox ID="commentsTextBox" runat="server"
Text='<%# Bind("comments") %>' TextMode="MultiLine"
Width="100%"></asp:TextBox></td></tr>
<tr><td>
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:www_sarnia_comConnectionString %>"
ProviderName="<%$
ConnectionStrings:www_sarnia_comConnectionString.ProviderName %>"
InsertCommand="insert into guestbook (firstname,lastname,city)
values (@firstname,@lastname,@city)">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
 
Hmm, you might want to try to use a GridView to configure the source.
Once information comes up on that, go to the FormView and make sure
that the value of "DataKeyNames" is the same as that of the GridView.
Fell free to contact me if you want more info. I don't visit here much.
=D (e-mail address removed)
 
Back
Top