Public Class Login
Private Shared con As New OleDb.OleDbConnection
Dim sql As String
Dim da As OleDb.OleDbDataAdapter
Dim ds As New DataSet
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text <> "fcf@gmail.com" Or TextBox2.Text <> "fcf1234567" Then
MsgBox("Wrong username or password!! Please try again!!", 0, "!!!")
Else
con.Open()
sql = "SELECT * FROM c_info"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "c_information")
Me.Hide()
Home.Label6.Show()
Home.Label6.Text = ds.Tables("c_information").Rows(0).Item(0)
Home.Button8.Show()
Home.Button6.Hide()
Home.Button9.Show()
Profile.Enabled = True
Profile.TextBox1.Text = ds.Tables("c_information").Rows(0).Item(0)
Profile.TextBox2.Text = ds.Tables("c_information").Rows(0).Item(1)
Profile.TextBox3.Text = ds.Tables("c_information").Rows(0).Item(2)
Profile.TextBox4.Text = ds.Tables("c_information").Rows(0).Item(3)
Profile.TextBox5.Text = ds.Tables("c_information").Rows(0).Item(4)
Profile.ComboBox1.Text = ds.Tables("c_information").Rows(0).Item(5)
End If
End Sub
我正在做一个登录系统,尝试打开数据库连接,然后以另一种形式关闭它,不知道怎么做...在这段代码中我输入了con.open(),但是当我运行时它两次,它说“当前连接仍然打开”
答案 0 :(得分:1)
3建议:
con
更改为Public Shared
或Protected Shared
(最好将其放在单独的课程/模块中);通过这种方式,您可以从所有表单和clases中访问它OleDb.OleDbConnection
上添加一个属性或在其构造函数上添加一个参数,并在创建第二个表单时从Form1传递它。