当我创建与我的数据库的odbc连接时,我直接从它给我的连接字符串中获取了路径。 Table1是我的表,数据库名为VideoGameDatabase。
Dim strPath6 As String = "Driver={Driver do Microsoft Access (*.mdb)};dbq=C:\USERS\KIRITO\DESKTOP\VideoGameDatabase.mdb;defaultdir=C:\USERS\KIRITO\DESKTOP;driverid=25;fil=MS Access;filedsn=C:\Users\Kirito\Desktop\VideoGameDatabase.dsn;maxbuffersize=2048;maxscanrows=8;pagetimeout=5;safetransactions=0;threads=3;uid=admin;usercommitsync=Yes"
Dim Connection2 As New System.Data.Odbc.OdbcConnection(strPath6)
Connection2.Open()
Dim cmd As OdbcCommand = New OdbcCommand("INSERT INTO Table1 " & _
"(Slot, Health, Gold, Level, Strength, Vitality, Agility, XP) " & _
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Connection2)
cmd.Parameters.Add("@Slot", OdbcType.VarChar, 255).Value = 1
cmd.Parameters.Add("@Health", OdbcType.VarChar, 255).Value = Battle.lblPlayerHealth.Text
cmd.Parameters.Add("@Gold", OdbcType.VarChar, 255).Value = Inventory.lblMoney.Text
cmd.Parameters.Add("@Level", OdbcType.VarChar, 255).Value = Inventory.lblLevel.Text
cmd.Parameters.Add("@Strength", OdbcType.VarChar, 255).Value = Stats.lblStrength.Text
cmd.Parameters.Add("@Vitality", OdbcType.VarChar, 255).Value = Stats.lblVitality.Text
cmd.Parameters.Add("@Agility", OdbcType.VarChar, 255).Value = Stats.lblAgility.Text
cmd.Parameters.Add("@XP", OdbcType.VarChar, 255).Value = Inventory.lblXP.Text
cmd.ExecuteNonQuery()
Connection2.Close()