Update database

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 5
Reputation: tdapower is an unknown quantity at this point 
Solved Threads: 0
tdapower tdapower is offline Offline
Newbie Poster

Update database

 
0
  #1
Aug 3rd, 2009
I connected a access database by usin codes, But when i add new data the data doesn't display in same time. it need to restart the programme. can I solve this?
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 47
Reputation: Nada_ward is an unknown quantity at this point 
Solved Threads: 0
Nada_ward Nada_ward is offline Offline
Light Poster

Re: Update database

 
0
  #2
Aug 3rd, 2009
use refresh()
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 132
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 13
babbu babbu is offline Offline
Junior Poster

Re: Update database

 
-1
  #3
Aug 3rd, 2009
can i plz c the code
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,264
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 582
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Update database

 
0
  #4
Aug 3rd, 2009
Welcome to DaniWeb tdapower! Please post the relevant code for your application on this thread so we can see where the problem is. when you post code be sure to use code tags:

[code=vb.net]
...code here
[/code]
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 5
Reputation: tdapower is an unknown quantity at this point 
Solved Threads: 0
tdapower tdapower is offline Offline
Newbie Poster

Re: Update database

 
0
  #5
Aug 5th, 2009
  1.  
  2. Imports System.Data.OleDb
  3. Public Class frmLecAdd
  4. Dim con As New OleDbConnection
  5. Dim ds As New DataSet
  6. Dim da As OleDb.OleDbDataAdapter
  7. Dim sql As String
  8.  
  9.  
  10. Dim rowNo As Integer
  11.  
  12.  
  13.  
  14. Private Sub pbUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbUpdate.Click
  15.  
  16.  
  17.  
  18. Dim cb As New OleDb.OleDbCommandBuilder(da)
  19. Dim mycmd As New OleDb.OleDbCommand
  20. Dim rows As Integer
  21.  
  22.  
  23. con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = database.mdb;"
  24. con.Open()
  25.  
  26. sql = "SELECT * FROM lec_info"
  27. da = New OleDb.OleDbDataAdapter(sql, con)
  28. da.Fill(ds, "myDB")
  29.  
  30.  
  31.  
  32. mycmd.CommandText = "INSERT INTO lec_info(lecturer_name,staff_no,course_name) VALUES('" & txtLname.Text & "','" & txtStaffNo.Text & "','" & cboCourses.Text & "')"
  33. mycmd.Connection = con
  34.  
  35. rows = mycmd.ExecuteNonQuery()
  36. con.Close()
  37. ds.AcceptChanges()
  38.  
  39. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 5
Reputation: tdapower is an unknown quantity at this point 
Solved Threads: 0
tdapower tdapower is offline Offline
Newbie Poster

Re: Update database

 
0
  #6
Aug 5th, 2009
This is my code is
when i add new record using this i have to restart my programme to see the new data.
pls help me...

  1.  
  2. Imports System.Data.OleDb
  3. Public Class frmLecAdd
  4. Dim con As New OleDbConnection
  5. Dim ds As New DataSet
  6. Dim da As OleDb.OleDbDataAdapter
  7. Dim sql As String
  8.  
  9.  
  10. Dim rowNo As Integer
  11.  
  12.  
  13.  
  14. Private Sub pbUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbUpdate.Click
  15.  
  16.  
  17.  
  18. Dim cb As New OleDb.OleDbCommandBuilder(da)
  19. Dim mycmd As New OleDb.OleDbCommand
  20. Dim rows As Integer
  21.  
  22.  
  23. con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = database.mdb;"
  24. con.Open()
  25.  
  26. sql = "SELECT * FROM lec_info"
  27. da = New OleDb.OleDbDataAdapter(sql, con)
  28. da.Fill(ds, "myDB")
  29.  
  30.  
  31.  
  32. mycmd.CommandText = "INSERT INTO lec_info(lecturer_name,staff_no,course_name) VALUES('" & txtLname.Text & "','" & txtStaffNo.Text & "','" & cboCourses.Text & "')"
  33. mycmd.Connection = con
  34.  
  35. rows = mycmd.ExecuteNonQuery()
  36. con.Close()
  37. ds.AcceptChanges()
  38.  
  39. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 132
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 13
babbu babbu is offline Offline
Junior Poster

Re: Update database

 
0
  #7
Aug 5th, 2009
u have to update the data table
  1. da.update(datatable)

u have used data adapter to retrieve data thn why dont u use it to insert as well

  1. Dim drNewRow As DataRow = DataTable.NewRow()
  2. drNewRow("lecturer_name") = txtLname.Text
  3. drNewRow("staff_no") = txtStaffNo.Text
  4. drNewRow("course_name") = cboCourses.Text
  5.  
  6. DataTable.Rows.Add(drNewRow)
  7. da.Update(DataTable)
Last edited by babbu; Aug 5th, 2009 at 2:43 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 5
Reputation: tdapower is an unknown quantity at this point 
Solved Threads: 0
tdapower tdapower is offline Offline
Newbie Poster

Re: Update database

 
0
  #8
Aug 9th, 2009
I tryied your code, but that doesn't work well
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 57
Reputation: emint is an unknown quantity at this point 
Solved Threads: 4
emint emint is offline Offline
Junior Poster in Training

Re: Update database

 
0
  #9
Aug 9th, 2009
everything are seems fine just need to update dataset
  1. rows = mycmd.ExecuteNonQuery()
  2. con.Close()
  3. ds.AcceptChanges()
  4. da.Update(ds)


should work fine.
Last edited by emint; Aug 9th, 2009 at 4:10 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 11
Reputation: Vivek_1986 is an unknown quantity at this point 
Solved Threads: 0
Vivek_1986 Vivek_1986 is offline Offline
Newbie Poster

@ tdapower

 
0
  #10
Aug 10th, 2009
Tryout this code(It's bit different and i't tested):


Imports System.data
Imports System.Data.OleDb
Public Class frmLectureRecords
    Dim con As OleDbConnection
    Dim cmd As OleDbCommand()
    Dim da As OleDb.OleDbDataAdapter
    Dim ds As New DataSet()
    Dim Sql As String

    Private Sub frmLectureRecords_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\college.mdb;Persist Security Info=False")
        con.Open()
        Sql = "SELECT * FROM lec_info"
        da = New OleDb.OleDbDataAdapter(Sql, con)
        da.Fill(ds, "lec_info")
        con.Close()
        DataGridView1.ClearSelection()
        ' Set the DataGridView properties to bind it to our data...
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "lec_info"
        DataGridView1.Columns(0).HeaderText = "Lecturer Name"
        DataGridView1.Columns(1).HeaderText = "Staff No"
        DataGridView1.Columns(2).HeaderText = "Course"
    End Sub
End Class
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC