数据库更新无效

时间:2013-11-05 03:20:15

标签: c#-to-vb.net

我知道你们会发现这很简单,但是有人可以告诉我为什么我会在许多网站上遵循每条指令时出现语法错误吗?

我的完整代码是:

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source = F:\Brett\Programming Projects\Roster\Roster.mdb"

    con.ConnectionString = dbProvider & dbSource
    con.Open()
    ' This is grabbing all the records from the listing table in the Roster Database
    sql = "Select * FROM Listing"
    ' Or selected columns
    'sql = "SELECT Listing.FName, Listing.LName FROM Listing"
    da = New OleDb.OleDbDataAdapter(sql, con)

    ' Populate the dataset with the data adaptor. This can be any name
    da.Fill(ds, "Roster")
    con.Close()

    MaxRows = ds.Tables("Roster").Rows.Count
    inc = -1

End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    Dim cb As New OleDb.OleDbCommandBuilder(da)
    Dim iRow As Integer = Me.Label1.Text
    Dim junk As Integer

    ds.Tables("Roster").Rows(iRow).Item(5) = Me.TextBox3.Text
    ds.Tables("Roster").Rows(iRow).Item(6) = Me.TextBox4.Text
    ds.Tables("Roster").Rows(iRow).Item(8) = Me.TextBox5.Text

    da.Update(ds, "Roster")

    'da.Update(ds)

End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Dim newtbl As DataTable
    Dim cb As New OleDb.OleDbCommandBuilder(da)
    Dim cmd As New OleDb.OleDbCommand

    newtbl = ds.Tables("Roster")

    Dim drCurrent As DataRow
    drCurrent = newtbl.NewRow()

    drCurrent(1) = "sfd"
    drCurrent(2) = "werter"

    newtbl.Rows.Add(drCurrent)

    da.Update(ds, "Roster")

End Sub

无论我做什么,我都会收到此错误消息。任何帮助将不胜感激,因为现在是两天......

我会告诉你我的错误,但像往常一样,一些花生不会让我没有一些废话..它说OleDbException未处理,Insert Into语句中的语法错误。

1 个答案:

答案 0 :(得分:0)

您是否可以尝试在try-catch块中包装数据库调用并检查返回异常的InnerXml?

这可能会为您提供有关您所犯错误的更多信息。