...

View Full Version : ADO.net - Inserting record problem



IOB
03-01-2007, 08:06 PM
When I use the proper SQL statements within ADO to insert a record into my test database using parameters (values from textboxes), nothing is passed at all and everything is null. However, if I pass a hard value, the table does recieve the data. I looked over my code a bunch of times but can't find one thing wrong as to why this is happening. Any help?


<%@ Import Namespace = "MySql.Data.MySqlClient"%>
<%@ Page Language="C#" Debug="true" %>
<Script Runat="server">



protected void submitClick(object s, EventArgs e){

MySqlConnection conn;
MySqlCommand comm;

conn=new MySqlConnection("Server=localhost;user id=testuser;pwd=password;database=test");


comm = new MySqlCommand(
"INSERT INTO Dev07 (cliID)" +
"VALUES (@cliID)", conn);

comm.Parameters.Add("@cliID",clientTextBox.Text);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();

}


</script>
<html>
<body>
<form Runat="Server">

<p>
Account Number
<asp:TextBox
Id="clientTextBox"
MaxLength="7"
Runat="Server" />
<p>
<asp:Button
Id="submit"
OnClick="submitClick"
Text="submit"
runat="server" />

</form>
</body>
</html>

Freon22
03-02-2007, 03:26 AM
I code VB not C# but I believe the Parameters are the same in both.


comm = new MySqlCommand(
"INSERT INTO Dev07 (cliID)" +
"VALUES (@cliID)", conn);

comm.Parameters.Add("@cliID",clientTextBox.Text);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();

Try this AddWithValues.


comm.Parameters.AddWithValue("@cliID", clientTextBox.Text)

nikkiH
03-02-2007, 02:20 PM
I had a problem with .NET 1.1 and parameters like this as well. Never did solve it.
Using 2.0, no problem with AddWithValue. So now I just use that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum