本文介绍了在vb.net中找不到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我点击按钮然后消息框显示消息找不到table0。 这意味着什么?我怎么能解决这个问题? ?? 私人 Sub butsea_Click(发件人作为 对象,e As EventArgs)句柄 butsea.Click Dim dset 正如 新 DataSet Dim da 作为 SqlDataAdapter Dim myCmd 作为 新 SqlCommand 尝试 myConn.ConnectionString = 数据源= THEONE \ PAGEH;初始目录= testdatabase;集成安全性=真; myConn.Open() Dim avalue 作为 字符串 =(InputBox( 输入学生ID, 搜索学生))。ToString txt_id.Text = avalue da = 新 SqlDataAdapter( SELECT * FROM studentdetails where student_id ='& txt_id.Text& ,myConn) 如果 dset.Tables( 0 )。Rows.Count> 0 然后 MsgBox( Record Found) Else MsgBox( 找不到记录) 结束 如果 Catch ex As 例外 MsgBox(ex.Message) 最后 myConn.Close() 结束 尝试 结束 Sub 解决方案 您在方法的顶部声明了一个DataSet,但是你没有实际上是c通过DataAdapter与数据库连接!尝试添加中间行: da =新SqlDataAdapter( SELECT * FROM studentdetails,其中student_id ='& txt_id。文字& ,myConn) da.Fill(dset) 如果 dset。表( 0 )。Rows.Count> 0 然后 Private Sub butsea_Click(发件人为对象,e为EventArgs)处理butsea.Click Dim dset As New DataSet Dim da As SqlDataAdapter Dim myCmd As New SqlCommand 尝试 myConn.ConnectionString = Data Source = THEONE\PARTH; Initial Catalog = testdatabase; Integrated Security = True; myConn.Open() Dim avalue as String =(InputBox( 输入学生ID, 搜索学生))。ToString txt_id.Text = avalue da =新的SqlDataAdapter( SELECT * FROM studentdetails,其中student_id ='& txt_id.Text& ,myConn) da.Fill(dset)如果是dset。表( 0 )。Rows.Count > 0 然后 MsgBox( Record Found) Else MsgBox( 找不到记录)结束如果 Catch ex As Exception MsgBox(ex.Message)最后 myConn.Close()结束尝试 结束子 when i was click on button then message box show message "cannot find table0."what does it means ???how can i solve this problem ???? Private Sub butsea_Click(sender As Object, e As EventArgs) Handles butsea.Click Dim dset As New DataSet Dim da As SqlDataAdapter Dim myCmd As New SqlCommand Try myConn.ConnectionString = "Data Source=THEONE\PARTH;Initial Catalog=testdatabase;Integrated Security=True;" myConn.Open() Dim avalue As String = (InputBox("Input Student Id", "Search Student")).ToString txt_id.Text = avalue da = New SqlDataAdapter("SELECT * FROM studentdetails where student_id= '" & txt_id.Text & "", myConn) If dset.Tables(0).Rows.Count > 0 Then MsgBox("Record Found") Else MsgBox("No Record Found") End If Catch ex As Exception MsgBox(ex.Message) Finally myConn.Close() End Try End Sub 解决方案 You declare a DataSet at the top of your method, but you don't actually connect it with the database via the DataAdapter! Try adding the middle line:da = New SqlDataAdapter("SELECT * FROM studentdetails where student_id= '" & txt_id.Text & "", myConn)da.Fill(dset)If dset.Tables(0).Rows.Count > 0 ThenPrivate Sub butsea_Click(sender As Object, e As EventArgs) Handles butsea.Click Dim dset As New DataSet Dim da As SqlDataAdapter Dim myCmd As New SqlCommand Try myConn.ConnectionString = "Data Source=THEONE\PARTH;Initial Catalog=testdatabase;Integrated Security=True;" myConn.Open() Dim avalue As String = (InputBox("Input Student Id", "Search Student")).ToString txt_id.Text = avalue da = New SqlDataAdapter("SELECT * FROM studentdetails where student_id= '" & txt_id.Text & "", myConn) da.Fill(dset) If dset.Tables(0).Rows.Count > 0 Then MsgBox("Record Found") Else MsgBox("No Record Found") End If Catch ex As Exception MsgBox(ex.Message) Finally myConn.Close() End Try End Sub 这篇关于在vb.net中找不到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 02:11