首先,我是一个初学者。 更多说明: 我正在用Vis编写此程序。基本访问数据库,获取值并保存信息。 该数据库是MS Access 2016数据库。 我有多种形式,在每种形式上输入不同的值。 我现在制作了一个ADD表单,将数据库中所有表单的所有数据写入。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim sqlconn As New OleDb.OleDbConnection
Dim sqlquery As New OleDb.OleDbCommand
Dim connString As String
Dim custname, custnum, cgender, pkind, pmodel, probear, meduse, tint, tinl, crema, cneed As String
Dim byear As Integer
connString = "Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Users\rolf\source\repos\AMEST_Audiology\AMEST_Audiology\bin\Debug\audiology.accdb"
sqlconn.ConnectionString = connString
sqlquery.Connection = sqlconn
sqlconn.Open()
sqlquery.CommandText = "INSERT INTO audiodat (custName,Custnum,cgender,pkind,pmodel,probear,meduse,tint,tinl,crema,cneed) Values (@custName,@custnum,@cgender,@pkind,@pmodel,@probear,@meduse,@tint,@tinl,@crema,@cneed)"
custname = FrmCust.custName
custnum = FrmCust.Custnum
cgender = FrmCust.CGender
byear = FrmCust.byear
pkind = FrmCust.pkind
pmodel = FrmCust.pmodel
probear = Frmhistory.probear
meduse = Frmhistory.meduse
tint = Frmhistory.tint
tinl = Frmhistory.tinl
crema = FrmClinic.crema
cneed = Frmsolution.cneed
sqlquery.Parameters.AddWithValue("@custname", custname)
sqlquery.Parameters.AddWithValue("@custnum", custnum)
sqlquery.Parameters.AddWithValue("@cgender", cgender)
sqlquery.Parameters.AddWithValue("@pkind", pkind)
sqlquery.Parameters.AddWithValue("@pmodel", pmodel)
sqlquery.Parameters.AddWithValue("@probear", probear)
sqlquery.Parameters.AddWithValue("@meduse", meduse)
sqlquery.Parameters.AddWithValue("@tint", tint)
sqlquery.Parameters.AddWithValue("@tinl", tinl)
' sqlquery.Parameters.AddWithValue("@oprobhis", oprobhis)
sqlquery.Parameters.AddWithValue("@crema", crema)
sqlquery.Parameters.AddWithValue("@cneed", cneed)
sqlquery.ExecuteNonQuery()
sqlconn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Frmprintdoc.Show()
Me.Close()
End Sub
它在字符串作用下一直有效,但是我无法保存数字或复选框状态。 它也不会真正将数据写入数据库,而只是写入tableadapter的内存中。我想念什么?