asp.net调用mysql存储过程
mycomm=newMySqlCommand("sp_luckdraw",myco);mycomm.CommandType=CommandType.StoredProce...
mycomm = new MySqlCommand("sp_luckdraw", myco);
mycomm.CommandType = CommandType.StoredProcedure;
MySqlParameter myParameter = new MySqlParameter("@prizeCode",MySqlDbType.VarChar, 50);
myParameter.Value = strValue.ToUpper();
myParameter.Direction = ParameterDirection.Input;
mycomm.Parameters.Add(myParameter);
MySqlParameter myParameter2 = new MySqlParameter("@result", MySqlDbType.Int32);
myParameter2.Direction = ParameterDirection.Output;
mycomm.Parameters.Add(myParameter2);
using (dr = mycomm.ExecuteReader(CommandBehavior.CloseConnection))
{
string strResult1 = myParameter2.Value.ToString();
while (dr.Read())
{
string strResult = dr["result"].ToString();
}
}
请我为什么传出参数myParameter2.Value是null,怎么解决。(存储过程在mysql数据库执行没问题) 展开
mycomm.CommandType = CommandType.StoredProcedure;
MySqlParameter myParameter = new MySqlParameter("@prizeCode",MySqlDbType.VarChar, 50);
myParameter.Value = strValue.ToUpper();
myParameter.Direction = ParameterDirection.Input;
mycomm.Parameters.Add(myParameter);
MySqlParameter myParameter2 = new MySqlParameter("@result", MySqlDbType.Int32);
myParameter2.Direction = ParameterDirection.Output;
mycomm.Parameters.Add(myParameter2);
using (dr = mycomm.ExecuteReader(CommandBehavior.CloseConnection))
{
string strResult1 = myParameter2.Value.ToString();
while (dr.Read())
{
string strResult = dr["result"].ToString();
}
}
请我为什么传出参数myParameter2.Value是null,怎么解决。(存储过程在mysql数据库执行没问题) 展开
2个回答
2016-02-23 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
类的调用方法:
public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
{
using (SqlConnection connection = new SqlConnection(strConn))
{
int result;
connection.Open();
SqlCommand command = BuildIntCommand(connection, storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
//Connection.Close();
return result;
}
}
Mysql的简单存储过程:
CREATE PROCEDURE `DELETEDB`(IN m_orgid char(12))
BEGIN
delete from hardwareinfo where orgid=m_orgid;
delete from addressinfo where orgid=m_orgid;
END
public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
{
using (SqlConnection connection = new SqlConnection(strConn))
{
int result;
connection.Open();
SqlCommand command = BuildIntCommand(connection, storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
//Connection.Close();
return result;
}
}
Mysql的简单存储过程:
CREATE PROCEDURE `DELETEDB`(IN m_orgid char(12))
BEGIN
delete from hardwareinfo where orgid=m_orgid;
delete from addressinfo where orgid=m_orgid;
END
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询