【发布时间】:2019-01-18 14:36:21
【问题描述】:
我正在为我们的论文制作一个学生管理系统。当我输入用户名和密码后单击登录按钮时,da.Fill(dt) 中出现此错误:
InvalidOperationException 未处理
Fill:SelectCommand.connection属性尚未初始化。
这是我在登录按钮中的代码
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
cs = "Data Source=.\SQLEXPRESS;Initial Catalog=demo;Integrated Security=True"
con = New SqlConnection(cs)
Dim username As String = TextBox1.Text
Dim password As String = TextBox2.Text
cmd = New SqlCommand("select username,password from login where
username='" + TextBox1.Text + "'and password'" + TextBox2.Text + "' ")
da = New SqlDataAdapter(cmd)
dt = New DataTable()
da.Fill(dt)
If (dt.Rows.Count > 0) Then
name = TextBox1.Text
MessageBox.Show("Login Successful", "success!",
MessageBoxButtons.OK, MessageBoxIcon.Information)
content.Show()
Else
MsgBox("Invalid Login Information!", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If
End Sub
End Class
当我点击登录按钮时,我应该会进入主页。
这是登录:
这就是家:
【问题讨论】:
-
欢迎来到 StackOverflow。我编辑了您的问题以将错误消息引用为文本。同样在标题中,我放置了更详细的错误消息。重要的是按字面输入文本而不是显示文本图像,因此它们是可搜索和可访问的。我还嵌入了图像,尽管最后两个对于那些调查你的问题的人来说不是那么有用。
-
谢谢。抱歉,这是我第一次在这里提问。
标签: mysql vb.net sqldataadapter