一段ATM登录代码 求说解……
int rowCount = -1;
string sql = "exe_proLogined";
try
{
SqlCommand cmd = new SqlCommand(sql, DBHelper.conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Acount", SqlDbType.VarChar, 30).Value = acount;
cmd.Parameters.Add("@passWord", SqlDbType.VarChar, 20).Value = pwd;
DBHelper.conn.Open();
rowCount = int.Parse(cmd.ExecuteScalar().ToString());
}
catch (Exception ex)
{
throw ex;
}
finally
{
DBHelper.conn.Close();
}
return rowCount;
[解决办法]
- C# code
int rowCount = -1; string sql = "exe_proLogined";\\存储过程 try { SqlCommand cmd = new SqlCommand(sql, DBHelper.conn);\\创建sqlcommand对象 cmd.CommandType = CommandType.StoredProcedure;\\设置类型为存储过程 cmd.Parameters.Add("@Acount", SqlDbType.VarChar, 30).Value = acount;\\为为存储过程参数赋值 cmd.Parameters.Add("@passWord", SqlDbType.VarChar, 20).Value = pwd;\\为为存储过程参数赋值 DBHelper.conn.Open();\\打开连接 rowCount = int.Parse(cmd.ExecuteScalar().ToString());\\执行返回结果 } catch (Exception ex) { throw ex; } finally { DBHelper.conn.Close();\\关闭连接 } return rowCount;