程序如下:
if( _daCommand == null)
{
throw new System.ObjectDisposedException(GetType().FullName);
}
SqlConnection connSLS = new SqlConnection(SOConfiguration.NeweggConnectionString);
_daCommand.SelectCommand=new SqlCommand("getsystemversion",connSLS);
_daCommand.SelectCommand.CommandType=CommandType.StoredProcedure;
_daCommand.SelectCommand.Parameters.Add(new SqlParameter(SystemVersion_PARM,SqlDbType.Char));
_daCommand.SelectCommand.Parameters[SystemVersion_PARM].Value=projectName;
_daCommand.SelectCommand.Parameters.Add(new SqlParameter("@Version",SqlDbType.VarChar));
_daCommand.SelectCommand.Parameters["@Version"].Direction=ParameterDirection.Output;
SqlDataReader reader;
string currentVersion;
try
{
_daCommand.SelectCommand.Connection.Open();
reader=_daCommand.SelectCommand.ExecuteReader();
reader.Close();
_daCommand.SelectCommand.Connection.Close();
currentVersion=_daCommand.SelectCommand.Parameters["@Version"].Value.ToString();
return currentVersion;
}
可是老是提示出错:Parameter 1: '@Version' of type: String, the property Size has an invalid size: 0
也即返回的参数值有问题,不知道是什么原因,帮忙啊,大家.
if( _daCommand == null)
{
throw new System.ObjectDisposedException(GetType().FullName);
}
SqlConnection connSLS = new SqlConnection(SOConfiguration.NeweggConnectionString);
_daCommand.SelectCommand=new SqlCommand("getsystemversion",connSLS);
_daCommand.SelectCommand.CommandType=CommandType.StoredProcedure;
_daCommand.SelectCommand.Parameters.Add(new SqlParameter(SystemVersion_PARM,SqlDbType.Char));
_daCommand.SelectCommand.Parameters[SystemVersion_PARM].Value=projectName;
_daCommand.SelectCommand.Parameters.Add(new SqlParameter("@Version",SqlDbType.VarChar));
_daCommand.SelectCommand.Parameters["@Version"].Direction=ParameterDirection.Output;
SqlDataReader reader;
string currentVersion;
try
{
_daCommand.SelectCommand.Connection.Open();
reader=_daCommand.SelectCommand.ExecuteReader();
reader.Close();
_daCommand.SelectCommand.Connection.Close();
currentVersion=_daCommand.SelectCommand.Parameters["@Version"].Value.ToString();
return currentVersion;
}
可是老是提示出错:Parameter 1: '@Version' of type: String, the property Size has an invalid size: 0
也即返回的参数值有问题,不知道是什么原因,帮忙啊,大家.
加参数长度
create proc semyear_returncmd(@frm_year varchar(50),
@frm_sem varchar(50),@rint int output)
as
begin
select @rint=count(*) from frm_semesteryear
where frm_year=@frm_year and frm_sem=@frm_sem
return
endGO得到存储过程传递回来的值:SqlCommand returnCmd = new SqlCommand("semyear_returncmd",scon);
returnCmd.Parameters.Add(new SqlParameter("@rint",SqlDbType.Int,6,ParameterDirection.Output,false,0,0,null,DataRowVersion.Default,null));
returnCmd.Connection.Open();
returnCmd.ExecuteNonQuery();
int i = int.Parse(returnCmd.Parameters["@rint"].Value.ToString());这些就能取得存储过程传递回来的值了。
returnCmd.CommandType = CommandType.StoredProcedure;
加在
returnCmd.Parameters.Add(.........);
前