我的错误是这样说的(从字符串“dept_id”转换为“boolean”类型无效)任何解决方案请 [英] My error says like this (conversion from string "dept_id" to type 'boolean' is not valid) any solutions please
本文介绍了我的错误是这样说的(从字符串“dept_id”转换为“boolean”类型无效)任何解决方案请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Private Sub dept_num_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dept_num.TextChanged
Dim con As SqlConnection = New SqlConnection("Data Source=S-MHAMEED\SQL2008RTWO;Initial Catalog=comp.task;User ID=...;Password=....")
Using (con)
Dim sqlCom As New SqlCommand()
sqlCom.Connection = con
sqlCom.CommandText = "Sel_dept"
sqlCom.CommandType = CommandType.StoredProcedure
Dim Dept_id As Boolean
con.Open()
Integer.TryParse(dept_num.Text, Dept_id)
sqlCom.Parameters.AddWithValue("Dept_Id", Integer.Parse(dept_num.Text))
'Dept_id = Convert.ToInt32(sqlCom.ExecuteScalar)
If ("Dept_id") = False Then
MessageBox.Show("your new record")
End If
End Using
End Sub
End Class
我尝试了什么:
i只是不知道请帮助
从字符串Dept_id转换为'Boolean' '无效
What I have tried:
i just don't know please help
Conversion from string "Dept_id" to type 'Boolean' is not valid
推荐答案
此处的比较
The comparison here
If ("Dept_id") = False Then
看起来很奇怪。您正在尝试将文本与布尔值进行比较。
根据评论的代码,您试图找出执行是否成功。该过程是否返回新的部门值。如果是这样,将它存储在变量中并使用错误处理(try ... catch)确保执行成功。
我相信通过本教程可能有所帮助你:正确执行数据库操作 [ ^ ]
这篇关于我的错误是这样说的(从字符串“dept_id”转换为“boolean”类型无效)任何解决方案请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文