private void button2_Click(object sender, EventArgs e)
{
string[] arr = new string[2];
arr[0] = textBox1.Text;
arr[1] = textBox2.Text;
strSQL = "insert into nm(nb,bb)values(@nb,@bb)";
con.Open();
com = new SqlCommand(strSQL, con);
com.Parameters.Add("@nb", SqlDbType.NVarChar).Value=arr[0].ToString();
com.Parameters.Add("@bb", SqlDbType.NVarChar).Value = arr[1].ToString();
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("ثبت شد");
textBox1.Text = "0";
textBox2.Text = "0";
textBox1.Focus();
}
محض اطمینان :
1- قبل از فرم لود
private string strSQL;
private SqlConnection con;
private SqlDataAdapter da;
private SqlCommand com;
2-در فرم لود
con = new SqlConnection();
con.ConnectionString = (@"data source=.\sqlexpress;Initial catalog=databasename;Integrated Security=true");