每次我試圖連接到數據庫,它給我這個error "The ConnectionString property has not been initialized"
「ConnectionString屬性尚未初始化」的錯誤在VB.NET
How can i avoid this error and make it work?
這裏是我的代碼:
Imports System.Data.OleDb
Public Class frmLoginPage
Dim con As New OleDbConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter("Select*from tblPassword", con)
da.Fill(dt)
Dim newRow As DataRow = dt.NewRow
With newRow
If .Item("Username") = txtUsername.Text And .Item("Password") = txtPassword.Text Then frmMainMenu.ShowDialog() Else MsgBox("The username or password you entered was incorrect, please try again!", MsgBoxStyle.Critical, "Information")
End With
End Sub
你能告訴我在哪裏把它寫在我的編碼中,以及如何使它合適,還有一點點帽子說「myconnectionString」,它說「'myconnectionString'沒有聲明。它可能無法訪問,因爲它的保護級別「,這是什麼意思? – user2201924
你已經有了你的代碼的第一行,其餘的可以放到你的'Button1_Click'方法中(只需將'myConnection'重命名爲'con')。 'myConnectionString'只是你的真正連接字符串的佔位符,對於SQL Server來說,這將是類似於「」服務器= myServerName \ myInstanceName;數據庫= myDataBase;用戶ID = myUsername;密碼= myPassword;「 – DeanOC
@ user2201924這個解決你的問題嗎?如果你需要更多的幫助,請問:) – DeanOC