using三种用法
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = null;
using (SqlConnection conn = new SqlConnection("server=.;database=Login;uid=sa;pwd=coder"))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "sql 语句";
cmd.Connection = conn;
conn.Open();
cmd.ExecuteScalar();
}
using (conn = new SqlConnection("连接字符串")) { }
conn = new SqlConnection("连接字符串");
using (conn) { }
}
SqlCommand认识
SqlCommand cmd=new SqlCommand(); cmd.Connetion=conn; cmd.CommandText="";
SqlCommand cmd = new SqlCommand("",conn);
SqlCommand cmd=new SqlCommand();cmd.Connection=conn;
SqlCommand cmd = conn.CreateCommand();