存储过程 怎么从c#里面运行一个存储过程,给他参数然后将结果村到一个变量里? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CREATE PROCEDURE GetCount @iReturn int outputASselect @iReturn =count(1) from t1return 111GO private void button1_Click_1(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=12345;"); SqlCommand cmd = new SqlCommand("GetCount", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] parm = {new SqlParameter("@iReturn",SqlDbType.Int), new SqlParameter("@XX",SqlDbType.NVarChar) }; //输出参数 parm[0] = cmd.Parameters.Add("@iReturn", SqlDbType.Int); parm[0].Direction = ParameterDirection.Output; //返回值 parm[1] = cmd.Parameters.Add("@XX", SqlDbType.Int); parm[1].Direction = ParameterDirection.ReturnValue; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); MessageBox.Show(parm[0].Value.ToString() + " " + parm[1].Value.ToString()); reader.Close(); conn.Close(); } SqlConnection conn = new SqlConnection(连接字符);SqlCommand cmd = new SqlCommand(存储过程名称);cmd.CommandType=CommandType.StoreProc;cmd.Parameters.add("参数名",类型);cmd.Parameters["参数名"].Direction = out或者input//out就是输出,input就是输入的一样大概的就是这样的(手动写的,有点单词可能错了) 过程设置 @return outparameters[index].Direction = ParameterDirection.Output;C#执行过程后string returnValue = parameters[index].Value.ToString(); 如何截取字符串的后两位 C#中Attributes,找了资料始终不明白,请假高手(一语中的) oracle与sql2000之间的数据导入导出问题 这个在C#如何写? 时间包月的算法 关于继承窗体的困惑 怎么将一个类库打包 where子句中类型品配问题(text类型与string类型) 唉,没办法,很菜的问题--写一个普通类,不能使用session吗? 求一个 C#比较全的基类,,,感谢!急急急!! 哈哈,不知道会不会急进了一点呢,嘻嘻,高手进来哦 Custom Control 和 Composite Control 在 .NET 里面啥区别啊?
@iReturn int output
ASselect @iReturn =count(1) from t1
return 111
GO private void button1_Click_1(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=12345;");
SqlCommand cmd = new SqlCommand("GetCount", conn); cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] parm = {new SqlParameter("@iReturn",SqlDbType.Int),
new SqlParameter("@XX",SqlDbType.NVarChar)
}; //输出参数
parm[0] = cmd.Parameters.Add("@iReturn", SqlDbType.Int);
parm[0].Direction = ParameterDirection.Output; //返回值
parm[1] = cmd.Parameters.Add("@XX", SqlDbType.Int);
parm[1].Direction = ParameterDirection.ReturnValue; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); MessageBox.Show(parm[0].Value.ToString() + " " + parm[1].Value.ToString()); reader.Close();
conn.Close();
}
SqlCommand cmd = new SqlCommand(存储过程名称);
cmd.CommandType=CommandType.StoreProc;
cmd.Parameters.add("参数名",类型);
cmd.Parameters["参数名"].Direction = out或者input//out就是输出,input就是输入的一样
大概的就是这样的(手动写的,有点单词可能错了)
parameters[index].Direction = ParameterDirection.Output;
C#执行过程后
string returnValue = parameters[index].Value.ToString();