开发者

Different ways on how to manipulate access database in vb.net?

I'm currently using system.data.oledb but I can't seem to make the update , search, & delete work fine. Are there any other ways on how to manipulate an ms access database in vb.net easier than my method? Here is my code for searching:

      Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\ACCESS DATABASE\search.mdb")       
    Dim cmd As OleDbCommand = New OleDbCommand("Select * from GH where IDNUMBER= '" &  TextBox12.Text & "' ", cn)

    cn.Open()

    Dim rdr As OleDbDataReader
    rdr = cmd.ExecuteReader




    If rdr.HasRows Then
        rdr.Read()
        NoAcc = rdr("IDNUMBER")
        If (TextBox12.Text = NoAcc) Then TextBox13.Text = rdr("NAME")
        If (TextBox12.Text = NoAcc) Then TextBox14.Text = rdr("DEPARTMENT")
        If (TextBox12.Text = NoAcc) Then TextBox15.Text = rdr("COURSE")

Then you will have to make the necessary changes before pressing update: This is the update code, which is defective(it really updates the data but then it will duplicate the previous data, and the updated data will have a different id number):

        Dim cb As New OleDb.OleDbCommandBuilder(da)


    ds.Tables("GH").Rows(INC).Item("NAME") = TextBox13.Text
    ds.Tables("GH").Rows(INC).Item("DEPARTMENT") = TextBox14.Text
    ds.Tables("GH").Rows(INC).Item("COURSE") = TextBox15.Text

    da.Update(ds, "GH")

  开发者_开发技巧      MsgBox("Data updated")


you can use this one for the update

    If nameoftable.Rows.Count <> 0 Then
        nameoftable.Rows(recordposition)("course_code") = textbox1.Text
        nameoftable.Rows(recordposition)("course_description") = textbox2.Text
        nameofyouradapter.Update(nameoftable)
    End If


You can call DAO code through com interop in vb.net. The DAO interface is designed to work with the JET database engine directly so in most cases offers better performance than using ado.net or ADO however it does tie you into JET to some degree.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜