各位,小弟在asp.net 用c#调用sql server2000存储过程,没有成功,程序没有返回值,a_t表中没有数据.请指教?过程:CREATE procedure da_proselect_d
@yf varchar(10),
@dwx varchar(40) outputas
select @dwx='ok';
begin
insert into a_t values(@yf);
end
print @dwxGO
在查询分析器中能够返回值"ok",且a_t中有值.但使用c#中没有成功
C#代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Windows.Forms;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string strConn = "server=testtest;uid=abcd;pwd=aaaaaa;database=test";
SqlConnection DbConnection = new SqlConnection(strConn);
SqlCommand Command = new SqlCommand("da_proselect_d", DbConnection);
DbConnection.Open(); Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add("@abc_a",SqlDbType.VarChar,10,"aaa");
Command.Parameters.Add("@abc_b", SqlDbType.VarChar,10,null);
Command.Parameters.Add("@Returnvalue", SqlDbType.VarChar);
Command.Parameters["@abc_b"].Direction = ParameterDirection.Output;
}
}
@yf varchar(10),
@dwx varchar(40) outputas
select @dwx='ok';
begin
insert into a_t values(@yf);
end
print @dwxGO
在查询分析器中能够返回值"ok",且a_t中有值.但使用c#中没有成功
C#代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Windows.Forms;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string strConn = "server=testtest;uid=abcd;pwd=aaaaaa;database=test";
SqlConnection DbConnection = new SqlConnection(strConn);
SqlCommand Command = new SqlCommand("da_proselect_d", DbConnection);
DbConnection.Open(); Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add("@abc_a",SqlDbType.VarChar,10,"aaa");
Command.Parameters.Add("@abc_b", SqlDbType.VarChar,10,null);
Command.Parameters.Add("@Returnvalue", SqlDbType.VarChar);
Command.Parameters["@abc_b"].Direction = ParameterDirection.Output;
}
}
解决方案 »
- 投票结果查看 假单问题
- 动态布局!
- 各位大哥帮帮忙有谁知道 xyProgressLG 控件,用JavaScript如何隐藏该控件!!!!在线等待...急!!!
- |M| 如何让我的类:public class MyPage: System.Web.UI.Page 在用户控件中可以引用
- gridview分页后的问题
- OA系统中文档管理和公文流转有何关系?(哪位大哥可以给一点关于OA开发方面的技术资料)
- javascript中访问datagird中的数据
- asp.net如何调用存储过程中批处理产生的多个结果集?
- 一辈子也许就这么一次机会(名牌大学计算机免费视频课件全面收看和下载)涉及面广vb\vc\java\asp.....
- 请问各位高手,如何在另一个页面得到cook传递的值,请告诉我怎么写,谢谢。
- 读取多张图片出问题了
- 字符串是以,相隔的数字的形式,如何去除其中相同的数字?
Command.Parameters.Add("@abc_b", SqlDbType.VarChar,10,null); 这句改下
Command.Parameters.Add("@abc_b", SqlDbType.VarChar,10);
或者
Command.Parameters.Add("@abc_b", SqlDbType.VarChar,10,DBNull.Value);
Command.Parameters.Add("@abc_b", SqlDbType.VarChar,10,null); 这个参数哪来的啊
换成
SqlParameter paramabc_b =new SqlParameter("@abc_b",sqldDbType.nvarchar,40);
paramabc_b.Direction=ParameterDirection.Output;
Command.Parameters.Add(paramabc_b);
Command.Parameters.Add("@abc_a",SqlDbType.VarChar,10,"aaa");
Command.Parameters.Add("@abc_b", SqlDbType.VarChar,10,null);
Command.Parameters.Add("@Returnvalue", SqlDbType.VarChar);
Command.Parameters["@abc_b"].Direction = ParameterDirection.Output; 一个一个说吧,首先参数名要对应
存储过程叫@yf 程序就叫@yf
存储过程有几个参数 程序就有几个。你的存储过程 只是有一个输入输入参数,没有返回值。
所以Command.Parameters["@abc_b"].Direction = ParameterDirection.Output; 去掉
还有 长度也要匹配
应该是这个去掉
Command.Parameters.Add("@yf",SqlDbType.VarChar,10,"aaa");
Command.Parameters.Add("@dwx", SqlDbType.VarChar,40,"");
Command.Parameters["@dwx"].Direction = ParameterDirection.Output;这样试试
SqlParameter yf =new SqlParameter("@yf",sqldDbType.nvarchar,10);
yf.SqlValue = "aaa";
yf.Direction=ParameterDirection.Input;
Command.Parameters.Add(yf);SqlParameter dwx =new SqlParameter("@dwx",sqldDbType.nvarchar,40);
dwx.SqlValue = "";
dwx.Direction=ParameterDirection.Output;
Command.Parameters.Add(dwx);
添加command.excecutenoqurey()或則....