0% found this document useful (0 votes)
70 views4 pages

Public Class Form1

This code defines a form that allows navigation through records in a database table. It opens a connection to an Access database, fills a dataset with data from a table, and provides buttons to move between records, add, update, and delete records. Text boxes on the form are populated with field values from the current record.

Uploaded by

Tanavi Khandpur
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views4 pages

Public Class Form1

This code defines a form that allows navigation through records in a database table. It opens a connection to an Access database, fills a dataset with data from a table, and provides buttons to move between records, add, update, and delete records. Text boxes on the form are populated with field values from the current record.

Uploaded by

Tanavi Khandpur
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Public Class Form1 Dim inc As Integer Dim MaxRows As Integer Dim con As New OleDb.

OleDbConnection Dim dbProvider As String Dim dbSource As String Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'Tanavi_vbDataSet.Table1' table. You can move, or remove it, as needed. Me.Table1TableAdapter.Fill(Me.Tanavi_vbDataSet.Table1) dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" dbSource = "Data Source = C:\Users\Khandpur\Documents\Visual Studio 2010\Projects\tanavi vb.mdb" con.ConnectionString = dbProvider & dbSource con.Open() sql = "SELECT * FROM Table1" da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "tanavivb") MsgBox("Database is now open") con.Close() MaxRows = ds.Tables("tanavivb").Rows.Count inc = -1 End Sub Private Sub NavigateRecords() txtID.Text = ds.Tables("tanavivb").Rows(inc).Item(0) txtCompanyName.Text = ds.Tables("tanavivb").Rows(inc).Item(1) txtContact_person.Text = ds.Tables("tanavivb").Rows(inc).Item(2) txtAddress.Text = ds.Tables("tanavivb").Rows(inc).Item(3) txtCity.Text = ds.Tables("tanavivb").Rows(inc).Item(4) txtState.Text = ds.Tables("tanavivb").Rows(inc).Item(5) txtCountry.Text = ds.Tables("tanavivb").Rows(inc).Item(6) txtPhone_Number.Text = ds.Tables("tanavivb").Rows(inc).Item(7) txtFax_Number.Text = ds.Tables("tanavivb").Rows(inc).Item(8) txtGoods_Offered.Text = ds.Tables("tanavivb").Rows(inc).Item(9) txtVendor_rating.Text = ds.Tables("tanavivb").Rows(inc).Item(10) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If inc <> MaxRows - 1 Then inc = inc + 1 NavigateRecords() Else

MsgBox("No More Rows") End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If inc > 0 Then inc = inc - 1 NavigateRecords() ElseIf inc = -1 Then MsgBox("No Records Yet") ElseIf inc = 0 Then MsgBox("First Record") End If

End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If inc <> MaxRows - 1 Then inc = MaxRows - 1 NavigateRecords() End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If inc <> 0 Then inc = 0 NavigateRecords() End If End Sub Private Sub Table1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.Validate() Me.Table1BindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.Tanavi_vbDataSet) End Sub

Private Sub Btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnclear.Click btncommit.Enabled = False Btnaddnew.Enabled = True btnupdate.Enabled = True btndelete.Enabled = True inc = 0 NavigateRecords() End Sub

Private Sub btncommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncommit.Click If inc <> -1 Then Dim cb As New OleDb.OleDbCommandBuilder(da) Dim dsNewRow As DataRow dsNewRow = ds.Tables("tanavivb").NewRow() dsNewRow.Item("ID") = txtID.Text() dsNewRow.Item("companyname") = txtCompanyName.Text() dsNewRow.Item("contact person") = txtContact_person.Text() dsNewRow.Item("Adress") = txtAddress.Text() dsNewRow.Item("City") = txtCity.Text() dsNewRow.Item("State") = txtState.Text() dsNewRow.Item("Country") = txtCountry.Text() dsNewRow.Item("Phone Number") = txtPhone_Number.Text() dsNewRow.Item("Fax Number") = txtFax_Number.Text() dsNewRow.Item("Goods Offered") = txtGoods_Offered.Text() dsNewRow.Item("Vendor rating") = txtVendor_rating.Text() ds.Tables("tanavivb").Rows.Add(dsNewRow) da.Update(ds, "tanavivb") MsgBox("New Record added to the Database") btncommit.Enabled = False Btnaddnew.Enabled = True btnupdate.Enabled = True btndelete.Enabled = True

End If End Sub Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click Dim cb As New OleDb.OleDbCommandBuilder(da) If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then MsgBox("Operation Cancelled") End If Exit Sub ds.Tables("tanavivb").Rows(inc).Delete() MaxRows = MaxRows - 1 inc = 0 NavigateRecords() da.Update(ds, "tanavivb") End Sub Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click Dim cb As New OleDb.OleDbCommandBuilder(da) ds.Tables("tanavivb").Rows(inc).Item(0) = txtID.Text() ds.Tables("tanavivb").Rows(inc).Item(1) = txtCompanyName.Text() ds.Tables("tanavivb").Rows(inc).Item(2) = txtContact_person.Text() ds.Tables("tanavivb").Rows(inc).Item(3) = txtAddress.Text() ds.Tables("tanavivb").Rows(inc).Item(4) = txtCity.Text() ds.Tables("tanavivb").Rows(inc).Item(5) = txtState.Text()

ds.Tables("tanavivb").Rows(inc).Item(6) = txtCountry.Text() ds.Tables("tanavivb").Rows(inc).Item(7) = txtPhone_Number.Text() ds.Tables("tanavivb").Rows(inc).Item(8) = txtFax_Number.Text() ds.Tables("tanavivb").Rows(inc).Item(9) = txtGoods_Offered.Text() ds.Tables("tanavivb").Rows(inc).Item(10) = txtVendor_rating.Text() da.Update(ds, "tanavivb") MsgBox("Data updated") End Sub Private Sub Btnaddnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnaddnew.Click btncommit.Enabled = True Btnaddnew.Enabled = False btnupdate.Enabled = False btndelete.Enabled = False txtCompanyName.Clear() txtID.Clear() txtCompanyName.Clear() txtContact_person.Clear() txtAddress.Clear() txtCity.Clear() txtState.Clear() txtCountry.Clear() txtPhone_Number.Clear() txtFax_Number.Clear() txtGoods_Offered.Clear() txtVendor_rating.Clear() End Sub End Class

You might also like