1、使用不带参构造函数
SqlCommand cmd = new SqlCommand(); cmd.Connection = SqlConnnection对象; cmd.CommandText=Sql语句;
2、使用带参构造函数
SqlCommand cmd = new SqlCommand(sql语句,SqlConnection对象);
3、调用SqlConnection对象的CreateCommand方法
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText=strSql;
sqlserver2012——SqlCommand创建对象的三种方法
原文:https://www.cnblogs.com/javier520/p/10946822.html