0

HI i am getting error on lbl.Visible = true and command.ExecuteNonQuery();

plz check and paste correct coding i doing new project plz help me.

  protected void Button1_Click1(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=RAVI-PCSQLEXPRESS;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 command = new SqlCommand();

            command.CommandText = ("insert into table_1 (id,name,address,phone,city)values(@id,@name,@address,@phone,@city");
            command.Parameters.Add("@id", SqlDbType.VarChar, 50);
            command.Parameters.Add("@name", SqlDbType.VarChar, 50);
            command.Parameters.Add("@address", SqlDbType.VarChar, 50);
            command.Parameters.Add("@phone", SqlDbType.VarChar, 50);
            command.Parameters.Add("@city", SqlDbType.VarChar, 50);

            command.Parameters["@id"].Value = TextBox1.Text;
            command.Parameters["@name"].Value = TextBox2.Text;
            command.Parameters["@address"].Value = TextBox3.Text;
            command.Parameters["@phone"].Value = TextBox4.Text;
            command.Parameters["@city"].Value = TextBox5.Text;

            lbl.Visible = true;

            command.ExecuteNonQuery();
             conn.Close();

        }

Edited by ravidaniweb: sentence missing

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by hericles
0

You haven't told us the error (which helps us for future reference) but I'm going to say the command object isn't working because you haven't provided it with the connection object. Do this with

command.Connection = conn;
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.