如何在vb.net中执行存储过程

编程入门 行业动态 更新时间:2024-10-25 14:23:47
本文介绍了如何在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").Value

to this:

TxtValue.Text = Convert.ToString(Cmd.Parameters("@val").Value)

更多推荐

如何在vb.net中执行存储过程

本文发布于:2023-10-26 09:28:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529764.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   如何在   vb   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!