I have created simple database project, using vb.net, ado.net, oledb, datatable, datagridview.

My program is working nice, I just need Help with how to add, delete, update and edit records. Can any one please and please help me in this case, or can provide any good tutorial or source code for it please.

I used following code

‘Namespaces
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Common


 ‘other declearations in Public class form

Public Class Form1


    Inherits System.Windows.Forms.Form


    Dim dtBook As DataTable
    Dim daBook As New OleDb.OleDbDataAdapter


    Dim Srch As String
    Dim MaxRowsBook As Integer

    Private DataTable As DataTable
    Private CurrRec As Integer = 0



‘ a function declaration for Connecting textboxes and datagridview to datatable

Public Function ClearBookTable()

        txtBookID.DataBindings.Clear()
        txtNameOfBook.DataBindings.Clear()
        txtCompanyID.DataBindings.Clear()
        txtAuthorName.DataBindings.Clear()

        txtBookID.DataBindings.Add("text", dtBook, "BookID")
        txtNameOfBook.DataBindings.Add("text", dtBook, "NameOfBook")
        txtCompanyID.DataBindings.Add("text", dtBook, "CompanyID")
        txtAuthorName.DataBindings.Add("text", dtBook, "AuthorName")
End Function



‘code for form load event

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim daBook As OleDb.OleDbDataAdapter



        dtBook = New DataTable(1)
        daBook = New OleDbDataAdapter("Select * from Books", "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Display Center Software\DisplayCenterData.mdb")
        daBook.Fill(dtBook)

        DataGridBook.DataSource = dtBook

        txtBookID.DataBindings.Add("text", dtBook, "BookID")
        txtNameOfBook.DataBindings.Add("text", dtBook, "NameOfBook")
        txtCompanyID.DataBindings.Add("text", dtBook, "CompanyID")
        txtAuthorName.DataBindings.Add("text", dtBook, "AuthorName")
End Sub


‘code for previous Button

  Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        Me.BindingContext(dtBook).Position -= 1
        CurrRec -= 1
    End Sub

‘code for next button
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Me.BindingContext(dtBook).Position += 1
        CurrRec += 1

    End Sub

‘code for first Button
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        MaxRowsBook = dtBook.Rows.Count
        Me.BindingContext(dtBook).Position = 0

    End Sub

‘code for last button
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        MaxRowsBook = dtBook.Rows.Count
        Me.BindingContext(dtBook).Position = MaxRowsBook

    End Sub

‘code for search button
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Srch = txtSearch.Text
        daBook = New OleDbDataAdapter("Select * From Books where NameOfBook like'" & Srch & "%'", "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Display Center Software\DisplayCenterData.mdb")

        dtBook = New DataTable(2)

        daBook.Fill(dtBook)
        DataGridBook.DataSource = dtBook

        ClearBookTable()

    End Sub

Recommended Answers

All 2 Replies

Check this,

http://www.codeproject.com/KB/database/simpledbreadwrite.aspx

But Dear Renukavani, it seems it is C# code, as it Starts with these words .... "Simple ADO.NET Database Read, Insert, Update and Delete using C#.."

Please Help with Vb.net ado.net Oledb Coding Concepts.. i have founded following Code but facing problem that it Adds and update database at once, when i want that first i should Click <add> button, Put Values in text Boxes, then when i Click <update> the database should be updated permenantly

my code is as follows

Dim conn As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= D:\Display Center Software\DisplayCenterData.mdb")



        conn.Open()



        Dim da As New OleDb.OleDbDataAdapter("Select * FROM Books", conn)


        Dim ds As New DataSet

        Dim dt As DataTable, row As DataRow

        Dim cb As New OleDb.OleDbCommandBuilder(da)

        da.Fill(ds)

        dt = ds.Tables(0)

        row = dt.NewRow



        row("BookID") = txtBookID.Text
        row("NameOfBook") = txtNameOfBook.Text
        row("CompanyID") = txtCompanyID.Text
        row("AuthorName") = txtAuthorName.Text



        dt.Rows.Add(row)

        da.Update(ds)



        MsgBox("1 Record Inserted")

        DataGridBook.DataSource = Nothing

        'dView()



        conn.Close()

please help also with Delete record

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.