I'm not sure what the problem is. I am not getting any errors, but I can't get this code to insert into my SQL db. I've checked the permissions on the database and table, and it looks fine.
Is there something wrong with this code? I'm trying to switch from VB to C#, so it's still new to me. I've used the connection string in another APP so I know it works.
If I'm not getting an asp.net error, does that point to a problem with the DB? Thanks.
protected
void Button1_Click(object sender,EventArgs e){
SqlConnection Conn;SqlCommand Command;
Conn =
newSqlConnection();Conn.ConnectionString =ConfigurationManager.AppSettings["ConnectionString"];
Command =newSqlCommand();
Command.CommandText =
"INSERT INTO [tbl_Test] ([test_name], [test_email]) VALUES (@.test_name, @.test_email)";Command.CommandType =
CommandType.Text;Command.Connection = Conn;
Command.Parameters.Add("test_name", tbName.Text);
Command.Parameters.Add("test_email", tbEmail.Text);try
{
Command.Connection.Open();
Command.ExecuteNonQuery();
}
catch (Exception ex){
lError.Text = ex.Message;
}
finally{
Command.Connection.Close();
pSubscribe.Visible =
lThanks.Visible =true;
}
Command.Parameters.Add("test_name", tbName.Text);
Command.Parameters.Add("test_email", tbEmail.Text);
should be
Command.Parameters.Add("@.test_name", tbName.Text);
Command.Parameters.Add("@.test_email", tbEmail.Text);
No comments:
Post a Comment