SqlConnection不需要OPEN()吗???
public class DBconn : System.ComponentModel.Component
{
SqlConnection MyConnection1;
public SqlConnection MyConnection
{
get
{
MyConnection1 =new SqlConnection(ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
return MyConnection1;
}
}
----
public DBconn DB= new DBconn();
string deleteCmd = "DELETE from person where uname = @uname";
SqlCommand myCommand = new SqlCommand(deleteCmd, DB.MyConnection);
myCommand.Parameters.Add(new SqlParameter("@uname", SqlDbType.VarChar,10));
myCommand.Parameters["@uname"].Value = DataGrid1.DataKeys[e.Item.ItemIndex];
myCommand.ExecuteNonQuery();
bangding();
结果却正常????
我知道SqlDataAdapter(“select *”,DB.MyConnection)
不需要特意的OPEN()
难道SqlCommand.ExecuteNonQuery();
也不需要吗 我以前用() 可是都需要啊