NET的小问题请看看,多谢各位~!
using (SqlDataReader dr = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, SQL_LOGIN_ACCOUNT, Parms))
{
if(dr.Read())
return new sm_MUserInfo(dr.GetInt32(0),dr.GetString(1),dr.GetString(2);
return null;
}
===========================ExecuteReader代码=======================
public static SqlDataReader ExecuteReader(string connString, CommandType cmdType, string cmdText,params SqlParameter[] cmdParms)
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(connString);
try
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch{
conn.Close();
return null;
}
}
==========================PrepareCommand代码=====================
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText,SqlParameter[] cmdParms)
{
&n