add,update record in VB.Net without using oledbcommand

  • 13 years ago
    Imports System.Data.OleDbPublic Class Form1    Dim da As OleDbDataAdapter    Dim ds As New DataSet    Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =c:\db1.mdb;")     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        'Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =c:\db1.mdb;")        da = New OleDbDataAdapter("Select * from student", con)        'Dim ds As New DataSet        con.Open()        da.Fill(ds, "student")        txtname.DataBindings.Add("text", ds, "student.name")        txtroll.DataBindings.Add("text", ds, "student.roll")        txtcourse.DataBindings.Add("text", ds, "student.course")    End Sub     Private Sub btnprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprev.Click        BindingContext(ds, "student").Position = BindingContext(ds, "student").Position - 1    End Sub     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click        BindingContext(ds, "student").AddNew()        MessageBox.Show("Successfully Inserted")    End Sub     Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click        BindingContext(ds, "student").RemoveAt(BindingContext(ds, "student").Position)    End Sub     Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click        BindingContext(ds, "student").Position = BindingContext(ds, "student").Position + 1    End Sub     Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click        Me.BindingContext(ds, "student").EndCurrentEdit()        da.Update(ds)    End Sub     Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click        BindingContext(ds, "student").Position = 0    End Sub     Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click        BindingContext(ds, "student").Position = BindingContext(ds, "student").Count - 1    End Sub     Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click        txtname.Clear()        txtroll.Clear()        txtcourse.Clear()    End SubEnd Class the code for btnadd, btndelete,btnupdate will not affect the record in the table. iam using VB.Net 2005 and Ms. Access Database name db1.mdb which is in c drive. Please give me the solution or codes of this problem without using oledbcommand. plz reply the solution as earliest as possible.

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook