????????int counter=mycommand.Parameters["@tempcounter"].Value;

来源:百度知道 编辑:UC知道 时间:2024/06/21 13:01:52
这一句是不正确的
怎么样获得参数tempcounter的值?

SqlConnection conn = new SqlConnection(Common.HomeConnString);//连接字符串

SqlCommand cmd = new SqlCommand("存储过程名", conn);//SqlCommand调用存储过程

cmd.CommandType = CommandType.StoredProcedure;//指明SqlCommand将要执行的是存储过程

SqlParameter yn = new SqlParameter("@YourName", System.Data.SqlDbType.VarChar, 20);//给存储过程添加参数,参数名为@YourName

cmd.Parameters.Add(yn);//加入参数
yn.Value = yourName;//给参数赋值

int counter=mycommand.Parameters["@tempcounter"].Value;这句在编译的时候应该就不能通过了,
mycommand.Parameters["@tempcounter"].Value应该是一个string类型,所以如果单单从数据转换这个角度看,你应该改成这样:
int counter=int32.Prase(mycommand.Parameters["@tempcounter"].Value);