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