0

hi i am getting error plz error

SqlConnection conn = new SqlConnection("Data Source=RAVI-PC\\SQLEXPRESS;Initial Catalog=personals;User ID=sa;password=sa;Integrated Security=True");
        SqlDataAdapter da = new SqlDataAdapter(" select * from table_2", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "table_1");
        conn.Open();
       SqlCommand SQLINSERT =new SqlCommand();
       command.Parameters = "insert into table_1(ID,name,address,phone,city)values('@id','@name','@address','@phone','@city')" ;
       SQLINSERT.Parameters.Add(("@ID",Textbox1.Text.ToLower)
       SQLINSERT.Parameters.Add(("@name",Textbox1.Text.ToLower)
       SQLINSERT.Parameters.Add(("@address",Textbox1.Text.ToLower)
       SQLINSERT.Parameters.Add(("@phone",Textbox1.Text.ToLower)
       SQLINSERT.Parameters.Add(("@city",Textbox1.Text.ToLower)
     SQLINSERT.ExecuteNonQuery()
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by __avd
0

It would be helpful to prove the error message. There could be typos, or you may be trying to insert into a field that is a primary key with auto increment, etc...

1

Remove single quotes around parameters.

SqlCommand SQLINSERT =new SqlCommand();
SQLINSERT.CommandText = "insert into table_1 (ID,name,address,phone,city) values (@id,@name,@address,@phone,@city)" ;
SQLINSERT.Connection=conn;
SQLINSERT.Parameters.AddWithValue("@ID",Textbox1.Text.ToLower());
SQLINSERT.Parameters.AddWithValue("@name",Textbox1.Text.ToLower());
SQLINSERT.Parameters.AddWithValue("@address",Textbox1.Text.ToLower());
SQLINSERT.Parameters.AddWithValue("@phone",Textbox1.Text.ToLower());
SQLINSERT.Parameters.AddWithValue("@city",Textbox1.Text.ToLower());
SQLINSERT.ExecuteNonQuery();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.