本文介绍了如何在vb中执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ConnectDatabase() Cmd =新SqlCommand( stockon2 ,Con) Cmd.CommandType = CommandType.StoredProcedure Cmd.Parameters.AddWithValue( @ hd,CInt( 14572 )) Cmd.Parameters( @ hd)。Direction = ParameterDirection.Input Cmd.Parameters.AddWithValue( @ dt,CInt(Txtdate.Text)) Cmd.Parameters( @ dt)。Direction = ParameterDirection.Input Cmd.Parameters.AddWithValue( @ rateonly,CInt(txtip.Text)) Cmd.Parameters( @ rateonly)。Direction = ParameterDirection.Input Cmd.Parameters.AddWithValue( @ qty,CInt( 0 )) Cmd.Parameters( @ qty)。Direction = ParameterDirection.Input Cmd.Parameters.Add( @ val ,SqlDbType.Float) Cmd.Parameters( @ val)。Direction = ParameterDirection .Output Cmd.ExecuteReader() TxtValue.Text = Cmd.Parameters( @ val )。价值 Con.Close()
i得到以下附加错误 从类型'dbnull到字符串的转换无效
解决方案看起来很明显 - 你的输出参数(@val)得到NULL为价值! 如果这是一个不可接受的结果,你必须检查y我们的SP。 如果这是可接受的结果,请更改此行: TxtValue.Text = Cmd.Parameters( @ val)。值
到此:
TxtValue.Text = Convert.ToString( Cmd.Parameters( @ VAL)。值的)ConnectDatabase() Cmd = New SqlCommand("stockon2", Con) Cmd.CommandType = CommandType.StoredProcedure Cmd.Parameters.AddWithValue("@hd", CInt(14572)) Cmd.Parameters("@hd").Direction = ParameterDirection.Input Cmd.Parameters.AddWithValue("@dt", CInt(Txtdate.Text)) Cmd.Parameters("@dt").Direction = ParameterDirection.Input Cmd.Parameters.AddWithValue("@rateonly", CInt(txtip.Text)) Cmd.Parameters("@rateonly").Direction = ParameterDirection.Input Cmd.Parameters.AddWithValue("@qty", CInt(0)) Cmd.Parameters("@qty").Direction = ParameterDirection.Input Cmd.Parameters.Add("@val", SqlDbType.Float) Cmd.Parameters("@val").Direction = ParameterDirection.Output Cmd.ExecuteReader() TxtValue.Text = Cmd.Parameters("@val").Value Con.Close()
i got below attached error Conversion from type 'dbnull to the string is not valid
解决方案 It seems to be obvious - your output parameter (@val) get NULL as value! If this is an unacceptable result you must check your SP. If this is an acceptable result change this line: TxtValue.Text = Cmd.Parameters("@val").Valueto this:
TxtValue.Text = Convert.ToString(Cmd.Parameters("@val").Value)更多推荐
如何在vb.net中执行存储过程
发布评论