I'm building a form that collects some info from the user (user name, password and type ) and I need to store this info into a table called USER that I created.
I'm using 3 text boxes and a button, when the user clicks the button I need to collect this info and store it into my table
when i click the button i get an error msg in this line (comm.ExecuteNonQuery(); )
what do i need to do?
here is the code
protectedvoid Button1_Click(object sender,EventArgs e){
string str ="data source=(local);initial catalog=NH_Project1;integrated security=true;";SqlConnection conn =newSqlConnection(str);
int rows;SqlCommand comm =newSqlCommand("INSERT INTO [USER](UserId, UserName, UserPassword, Type)VALUES" +
"@.UsrName,@.UsrPass,@.UsrType", conn);comm.CommandType =CommandType.Text;
comm.Parameters.AddWithValue("@.UsrName",TextBox1.Text);comm.Parameters.AddWithValue("@.UsrPass",TextBox2.Text);
comm.Parameters.AddWithValue("@.UsrType", TextBox3.Text);conn.Open();
rows= comm.ExecuteNonQuery();
conn.Close();
comm.Parameters.AddWithValue("@.UsrName",TextBox1.Text);comm.Parameters.AddWithValue("@.UsrPass",TextBox2.Text);
louayazar:
comm.Parameters.AddWithValue("@.UsrType", TextBox3.Text);
Remove the "@." symbol from your AddWithValue calls. Also, I'd recommend enclosing your ExecuteNonQuery call within a Try/Catch block so you can capture any errors in the future.
|||Hii
I tried to remove the "@." like what you said but that doesn't work, I still have the same error MSG when clicking the button.
|||
Then make sure to put your ExecuteNonQuery call into a Try/Catch block and see what exception you get. This should help you find out what's going on.
|||that was helpful, thanks a bunch
No comments:
Post a Comment