Friday, April 17, 2015

SQL connection and command

s = System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString;
        SqlConnection c = new SqlConnection(s);
        c.Open();
        SqlCommand cmd = new SqlCommand("insert into sample(name) values(@name)", c);
        cmd.Parameters.Add("@name", TextBox1.Text);
        cmd.ExecuteNonQuery();
        c.Close();

No comments:

Post a Comment