我正在开发我的第一个数据库程序,但无法在 access 数据库中更新数据。这是winform上“添加条件”按钮的代码。
Dim TaxConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ConfigurationManager.AppSettings("Database")
Dim dbConnection As OleDbConnection = New OleDbConnection(TaxConnStr)
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
Try
dbConnection.Open()
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO UserCriteria ( UserName, State, County, Type, Amount, Rank) VALUES ( @UserName, @State, @County, @Type, @Amount, @Rank)"
Me.DataGridView1.DataSource = dt
cmd.ExecuteNonQuery()
dt.Columns.Add("UserName")
dt.Columns.Add("State")
dt.Columns.Add("County")
dt.Columns.Add("Type")
dt.Columns.Add("Amount")
dt.Columns.Add("Rank")
dt.Rows.Add(New String() {
boxAssignTo.Text, _
boxState.Text, _
boxCounty.Text, _
boxAmount.Text, _
boxType.Text, _
boxRank.Text})
Catch ex As Exception
Finally
dbConnection.Close()
End Try
我知道我错过了什么或做错了,所以我请求你大师的指导。