Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. Dim dt As New DataTable()
  2. Dim rowindex As Integer = 0
  3. Dim connstr As String = "provider=microsoft.jet.oledb.4.0;" & "data source=IS420Project1.mdb"
  4. Dim sqlstr As String = "select * from Customers"
  5.  
  6. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
  7. dt.Clear()
  8. Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
  9. dataAdapter.Fill(dt)
  10. dataAdapter.Dispose()
  11. End Sub
  12.  
  13. Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
  14.  
  15. Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
  16. Dim i, cid As Integer
  17. Dim cFname As String
  18. Dim cLname As String
  19. Dim cGen As String
  20. Dim cCity As String
  21. Dim cCountry As String
  22. Dim rw As DataRow
  23. Dim commandbuilder As New OleDb.OleDbCommandBuilder(dataAdapter)
  24. 'Add a new row to the Customer table.
  25. rw = dt.NewRow
  26. cid = txtCus.Text
  27. cFname = txtFirst.Text
  28. cLname = txtLast.Text
  29. cGen = txtGen.Text
  30. cCity = txtCity.Text
  31. cCountry = txtCountry.Text
  32. rw.Item("CusID") = cid
  33. rw.Item("First Name") = cFname
  34. rw.Item("Last Name") = cLname
  35. rw.Item("CGender") = cGen
  36. rw.Item("City") = cCity
  37. rw.Item("Country") = cCountry
  38. Try
  39. dt.Rows.Add(rw)
  40. 'Update the Customer table in the IS420Project1 database.
  41. i = dataAdapter.Update(dt)
  42. Catch ex As Exception
  43. MessageBox.Show(ex.Message)
  44. End Try
  45. 'Displays number of rows updated.
  46. txtCus.Text = ""
  47. txtFirst.Text = ""
  48. txtLast.Text = ""
  49. txtGen.Text = ""
  50. txtCity.Text = ""
  51. txtCountry.Text = ""
  52. txtCus.Focus()
  53. MessageBox.Show("no of rows updated=" & i)
  54. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement