62,243
社区成员




SqlCommand myCmd = new SqlCommand();
myCmd.Connection = myConn;
myCmd.CommandText = strProcName;
myCmd.CommandType = CommandType.StoredProcedure;
SqlConnection myConn = GetConnection();
SqlCommand myCmd = new sqlCommand(strProcName,myConn);
myCmd.CommandType = CommandType.StoredProcedure;
仍然提醒可以简化,可是public SqlCommand();
public SqlCommand(string cmdText);
public SqlCommand(string cmdText, SqlConnection connection);
public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction transaction);
重载中并没有存储过程的初始化方法啊,还怎么简化呢?将CommadnType注释了倒是不提醒了,可是达不到效果了。SqlCommand myCmd = new SqlCommand
{
Connection = myConn,
CommandText = strProcName,
CommandType = CommandType.StoredProcedure
};
// 或者
SqlCommand myCmd = new SqlCommand(strProcName, myConn) {CommandType = CommandType.StoredProcedure};