943,987 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 2264
  • VB.NET RSS
Dec 29th, 2008
0

Add New Record

Expand Post »
hi,

I have Created a vb.net Application with MS ACCESS DATABASE, everything is working fine, But, There is a small problem . Everytime i ADD a new record it saves succesfully
but i can only view that particular saved data only after restarting the application..Pls Help me

******************************************************

Imports System.Data

Public Class frmdetail
Inherits System.Windows.Forms.Form

Dim inc As Integer
Dim maxrows As Integer
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String

Private Sub frmdetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source = C:\Documents and Settings\Acer\Desktop\CounsellingSystem\counselling.mdb"
con.Open()

sql = "select * from counselling"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "counselling")

con.Close()

maxrows = ds.Tables("counselling").Rows.Count
inc = -1

End Sub

Private Sub navigaterecords()

txtname.Text = ds.Tables("counselling").Rows(inc).Item(1)
txtcname.Text = ds.Tables("counselling").Rows(inc).Item(2)
txtnpos.Text = ds.Tables("counselling").Rows(inc).Item(3)

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("counselling").NewRow()


dsnewrow.Item(1) = txtname.Text
dsnewrow.Item(2) = txtcname.Text
dsnewrow.Item(3) = txtnpos.Text

ds.Tables("counselling").Rows.Add(dsnewrow)
da.Update(ds, "counselling")
MsgBox("New Record Added!")
Endclass

End Class

***************************************************
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Evil03 is offline Offline
9 posts
since Dec 2008
Dec 30th, 2008
0

Re: Add New Record

yes this happens because the control you are using is not eligible to update its data everytime. So what do you need to do is to update the data that is shown every time that you add a row.

you can do this by executing the same code that you have written.


Happy X-mas & Coding!
Reputation Points: 11
Solved Threads: 12
Junior Poster
Alexpap is offline Offline
117 posts
since Sep 2008
Dec 30th, 2008
0

Re: Add New Record

Click to Expand / Collapse  Quote originally posted by Alexpap ...
yes this happens because the control you are using is not eligible to update its data everytime. So what do you need to do is to update the data that is shown every time that you add a row.

you can do this by executing the same code that you have written.


Happy X-mas & Coding!
Hi ALex...

Execute Control!>.....could you pls give me an example ?

Merry X-Mas n Year 09 dude.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Evil03 is offline Offline
9 posts
since Dec 2008
Jan 2nd, 2009
0

Re: Add New Record

first you should tell me what control are u using so as to write the code for the specific control....
Reputation Points: 11
Solved Threads: 12
Junior Poster
Alexpap is offline Offline
117 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Save password...plz help
Next Thread in VB.NET Forum Timeline: Creation of *.exe from VS2005





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC