gpt4 book ai didi

vb.net - .net : how to evaluate this error

转载 作者:行者123 更新时间:2023-12-03 08:14:08 25 4
gpt4 key购买 nike

我是vb.net的新手,正在尝试创建登录表单,但是在运行此代码时出现错误msg("ExecuteReader: Connection property has not been initialized.")

Imports System
Imports System.Data
Imports System.Data.OleDb

Public Class Form1
Dim con As New System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbCommand
Dim da As System.Data.OleDb.OleDbDataAdapter
Dim sdr As System.Data.OleDb.OleDbDataReader

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dbprovider As String = "Provider=Microsoft.jet.OleDb.4.0;"
Dim dbsource As String = "Data Source=C:\Users\RAJKRI\Documents\Visual Studio 2008\Projects\Banking System.mdb"
con.ConnectionString = dbprovider & dbsource
con.Open()
cmd.Connection = con
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\RAJKRI\Documents\Visual Studio 2008\Projects\Banking System.accdb")

cmd = New OleDb.OleDbCommand("SELECT * FROM Login WHERE Empid = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "' , con")
sdr = cmd.ExecuteReader()
If (sdr.Read() = True) Then
Form2.Show()
TextBox1.Text = ""
TextBox2.Text = ""

Else
MessageBox.Show("Invalid Employee Id/Password")

End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class

最佳答案

您会将连接对象作为文本追加到查询中。更改

cmd = New OleDb.OleDbCommand("SELECT * FROM Login WHERE Empid = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "' , con")


cmd = New OleDb.OleDbCommand("SELECT * FROM Login WHERE Empid = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'" , con)

(区别在最后)

关于vb.net - .net : how to evaluate this error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19873013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com