Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim dt As New DataTable()
- Dim rowindex As Integer = 0
- Dim connstr As String = "provider=microsoft.jet.oledb.4.0;" & "data source=IS420Project1.mdb"
- Dim sqlstr As String = "select * from Customers"
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
- dt.Clear()
- Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
- dataAdapter.Fill(dt)
- dataAdapter.Dispose()
- End Sub
- Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
- Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
- Dim i, cid As Integer
- Dim cFname As String
- Dim cLname As String
- Dim cGen As String
- Dim cCity As String
- Dim cCountry As String
- Dim rw As DataRow
- Dim commandbuilder As New OleDb.OleDbCommandBuilder(dataAdapter)
- 'Add a new row to the Customer table.
- rw = dt.NewRow
- cid = txtCus.Text
- cFname = txtFirst.Text
- cLname = txtLast.Text
- cGen = txtGen.Text
- cCity = txtCity.Text
- cCountry = txtCountry.Text
- rw.Item("CusID") = cid
- rw.Item("First Name") = cFname
- rw.Item("Last Name") = cLname
- rw.Item("CGender") = cGen
- rw.Item("City") = cCity
- rw.Item("Country") = cCountry
- Try
- dt.Rows.Add(rw)
- 'Update the Customer table in the IS420Project1 database.
- i = dataAdapter.Update(dt)
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- 'Displays number of rows updated.
- txtCus.Text = ""
- txtFirst.Text = ""
- txtLast.Text = ""
- txtGen.Text = ""
- txtCity.Text = ""
- txtCountry.Text = ""
- txtCus.Focus()
- MessageBox.Show("no of rows updated=" & i)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement