proc p_outNum
@NAME as varchar(20) outputasset nocount on
SELECT @NAME =LN FROM A WHERE ID ='1'return @NAMEset nocount offstring LN=null;
string SQL="p_outNum";System.Data.SqlClient.SqlCommand comm=Comm(SQL);
comm.CommandType=CommandType.StoredProcedure;
comm.Parameters.Add("@NAME",System.Data.SqlDbType.VarChar,20);
comm.Parameters["@NAME"].Direction=ParameterDirection.Output;
comm.ExecuteNonQuery();
LN=comm.Parameters["@NAME"].Value.ToString();为什么会报出以下错误
{"Syntax error converting the varchar value 'T' to a column of data type int." }
请问要如何修改才能获取存储过程返回的数
@NAME as varchar(20) outputasset nocount on
SELECT @NAME =LN FROM A WHERE ID ='1'return @NAMEset nocount offstring LN=null;
string SQL="p_outNum";System.Data.SqlClient.SqlCommand comm=Comm(SQL);
comm.CommandType=CommandType.StoredProcedure;
comm.Parameters.Add("@NAME",System.Data.SqlDbType.VarChar,20);
comm.Parameters["@NAME"].Direction=ParameterDirection.Output;
comm.ExecuteNonQuery();
LN=comm.Parameters["@NAME"].Value.ToString();为什么会报出以下错误
{"Syntax error converting the varchar value 'T' to a column of data type int." }
请问要如何修改才能获取存储过程返回的数
SqlConnection con=new SqlConnection();
con.open();//
然后:
SqlCommand com=new SqlCommand(SQL,con); //SQL为楼主的存储过程名.
下面照旧就行.
@Name 没有赋值
上面的SqlConnection con=new SqlConnection();
改为:
SqlConnection Con=new SqlConnection("Server=(local);Integrated Security=true;Database="所用的数据库"";
返回的值的类型相同或者长度相等.
现在要实现的是LN=@NAME在C#中显示出来就行了
存储过程的返回值是Int型,你返回字符串当然有问题了。@NAME 这个不用直接返回的。
LZ检查一下,它提示你的LN列为int类型
你已经把@NAME声明为output 不需要return 的,而且return 只能返回int值