Private Sub OK_Click(sender As System.Object,e As System.EventArgs)处理OK.Click
If TextBox1.Text = "1234" Then
' This is the connection. You have to have this exact string, except "E:\Documents\notekeeper.mdb" will be the path to your thing instead
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=N:\Visual Studio 2010\Projects\Maths System Aid\Maths System Aid\Database7.mdb;User=;Password=;")
Try
conn.Open()
Catch ex As Exception
MsgBox("Cannot open database")
End Try
' The SQL statement / command
Dim cmd = New OleDbCommand("Insert INTO Student ([First Name], [Surname], [Username], [Password]) VALUES "("" & TextBox5.Text & "," & TextBox4.Text & "," & TextBox3.Text & "," & TextBox2.Text & "" & ")"), conn)
cmd.ExecuteNonQuery() ' Use ExecuteReader() to execute SELECT statements, but ExecuteNonQuery() for others
' Basically, the reader is like an array of all of the records that have been returned by the database
Me.Close()
StudentLogin.Show()
Else
MsgBox("Enter The Correct Confirmation code")
End If
End Sub
我的问题是它找不到我的数据库文件。我遵循了这条路,这是正确的。什么是问题的任何想法?
答案 0 :(得分:0)
我还没有在相当长的一段时间内完成这项任务,但是在你的表格顶部你应该首先运行一些进口
imports system.data
然后你应该这样定义:
dim conn as new oledb.oledbconnection
我在您的代码中注意到的另一个问题是您正在使用Jet提供程序,如果内存正确提供,则只能使用.accdb扩展名与新数据库一起使用。尝试将其更改为访问中的accdb ..我会快速查看它,看看我能想到什么。希望这至少有帮助。如果您遇到问题,可以选择其他提供商:
("Provider=Microsoft.ACE.OLEDB.12.0.......
答案 1 :(得分:0)
此路径是本地磁盘还是网络磁盘?是在另一台计算机或映射的网络驱动器上?
我连接的方式是
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:\data\database.mdb;Jet OLEDB:Database Password=******;"
con.ConnectionString = dbProvider & dbSource
con.open()
con.close()
这应该是完美的,但如果你有一个
,请使用你的路径和密码