我想在访问中添加一个新值,但是当我运行它时,它会插入最后查看的数据

时间:2014-09-16 17:06:25

标签: asp.net vb.net

Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If btnAdd.Text = "Add" Then
            btnAdd.Text = "Insert"

        txtFName.Text = ""
        txtLName.Text = ""
    ElseIf btnAdd.Text = "Insert" Then
        Dim cb As New OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow
        dsNewRow = ds.Tables("table").NewRow()

        dsNewRow.Item("First_Name") = txtFName.Text
        dsNewRow.Item("Last_Name") = txtLName.Text

        ds.Tables("table").Rows.Add(dsNewRow)
        da.Update(ds, "table")
        MsgBox("Adding record success")
        btnAdd.Text = "Add"
        conx()
        display()
    End If
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    dbProvider = "PROVIDER=Microsoft.Ace.OLEDB.12.0;"
    dbSource = "Data Source =" & Server.MapPath("CookiesDBase.accdb") & ""
    con.ConnectionString = dbProvider & dbSource

    conx()
    If Request.Cookies("cookies") Is Nothing Then
        Response.Cookies("cookies").Value = count
        Response.Cookies("cookies").Expires = Date.Now.AddDays(2)
    End If

    maxrows = ds.Tables("table").Rows.Count - 1
    count = Request.Cookies("cookies").Value
    display()
End Sub

0 个答案:

没有答案