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()

Recommended Answers

All 2 Replies

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...

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.