Results 1 to 4 of 4

Thread: adding new data to database

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    2

    adding new data to database

    hi, when i click the add button it says successful but when i look up in the database nothings added..

    its have 2 textboxes for firstname and surname
    1 button for add
    my table is compose of fields FirstName and Surname
    how can i solve this?
    here's my code... anyway thanks in advance
    Code:
    Public Class Form1
        Dim inc 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
    
            dbprovider = "Provider=Microsoft.JET.OLEDB.4.0;"
            dbsource = "Data Source=C:\AddressBook.mdb"
            con.ConnectionString = dbprovider & dbsource
    
            con.Open()
    
            sql = "SELECT * FROM tblContacts"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "AddressBook")
            con.Close()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow
            dsNewRow = ds.Tables("AddressBook").NewRow()
            dsNewRow.Item("FirstName") = TextBox1.Text
            dsNewRow.Item("Surname") = TextBox2.Text
            da.Update(ds, "AddressBook")
            MsgBox("New Record added to the Database")
    
        End Sub
    End Class
    Last edited by cutie0407; Jan 30th, 2010 at 12:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width