Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,097 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,831 people online right now. Registration is fast and FREE... Join Now!




updating tables in datasets in other forms

2 Pages V  1 2 >  
Reply to this topicStart new topic

updating tables in datasets in other forms, vb.net / data

Hanzie
1 Jun, 2008 - 03:21 AM
Post #1

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 92


My Contributions
HELP, I'm losing faith in me being able to code!

I'm having a application which holds data in different tables.

I'm having multiple forms for putting in the different data.
The forms have datagridviews where the datasources are tables in self-made datasets.

But now i'm totally confused about how to update a table in a dataset in another form when somebody has entered new data in a form.

Please look at the folowing:

I have a form called "Verzendbrief" which has a datagridview "TekVanBedrijvenDataGridView".
The datagridview is filled with data through the folowing code:

CODE

'Get connection string
        Dim strconnectionstring As String = My.Settings.DocRegData2ConnectionString
        'Create SqlConnection
        Dim objconnection As New SqlConnection(strconnectionstring)
        'Create SqlCommand  
        Dim objcommand As New SqlCommand("GetBladnummerNaamTekening2", objconnection)
        objcommand.CommandType = CommandType.StoredProcedure

        'Set the SelectCommand property of our adapter  
        objdataAdapter.SelectCommand = objcommand

        'Fill the DataSet using the SqlDataAdapter  
        objdataAdapter.Fill(objdatasetTekeningen, "Tekeningenbedrijven")

        TekVanBedrijvenDataGridView.AutoGenerateColumns = True
        TekVanBedrijvenDataGridView.DataSource = objdatasetTekeningen.Tables("Tekeningenbedrijven")
      


With this code the datagridview is filled correctly with the last data.

But now I also have another form for entering new data which also has to be displayed in the above mentioned datagridview.
When the new data is entered how do i update the above mentioned table from a dataset.

I have the folowing code, is this correctly:

CODE

'code where new data is entered in different tables..........

'Renew dataview on frmVerzendbrief because of new data
        My.Forms.FrmVerzendbrief.objdataAdapter.Update(My.Forms.FrmVerzendbrief.objdatasetTekeningen, "Tekeningenbedrijven")
        My.Forms.FrmVerzendbrief.objdataAdapter.Fill(My.Forms.FrmVerzendbrief.objdatasetTekeningen, "Tekeningenbedrijven")



When i check the tables the new data is entered correctly.

But in the datagridview first the old data is being displayed and under the old data the new data is being displayed. So the datagridview is showing double data?!?!?! WHY??

Please, please help!! Thnx in advanced
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 05:44 AM
Post #2

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
what kind of database are you using? access?

well.. if you invoke a refresh method or something like requery should do the job.. or better yet disconnect from the database and reconnect again to make sure new infos were being displayed..
User is offlineProfile CardPM
+Quote Post

Hanzie
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 06:08 AM
Post #3

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 92


My Contributions
Thnx for the reply, i'm using sql-server 2005.
I close the connection and re-open as you can see. That doesn't do the job!

Any help?
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 06:42 AM
Post #4

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
wOOt.. i'm in the wrong forum.. I thought this was vb6.. well.. but the logic is still the same except for the syntax of course..


well.. did you refresh the grid? requery the grid? disconnect and reconnect the database from the grid?

is there a method that can erase the content of the datagrid.. like datagrid.clear or something.. in that way.. you're always sure that the datagrid doesnt contain any data before you fill it with newer data..

This post has been edited by mensahero: 1 Jun, 2008 - 06:45 AM
User is offlineProfile CardPM
+Quote Post

Hanzie
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 07:00 AM
Post #5

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 92


My Contributions
I don't know of a codeline that refreshes the datagridview.
I know the tableadapter.update command and the tableadapter.fill command. These however don't do the job.

When I close the application and start it up again then the new data is shown correctly.

I will start looking on google again.
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 08:06 AM
Post #6

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions

well try disconnecting the datagrid from the database... then refresh the form then attach the updated db again.. like..

datagrid.datasource = nothing
me.refresh
datagrid.datasource = updateddatabase
me.refresh

thats just a pseudo code.. but probably that would work..
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 10:23 AM
Post #7

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Try clearing the dataset of data before you fill it the second time.

CODE

'code where new data is entered in different tables..........

'Renew dataview on frmVerzendbrief because of new data
My.Forms.FrmVerzendbrief.objdataAdapter.Update(My.Forms.FrmVerzendbrief.objdatasetTekeningen, "Tekeningenbedrijven")
My.Forms.FrmVerzendbrief.objdatasetTekeningen.Clear()
My.Forms.FrmVerzendbrief.objdataAdapter.Fill(My.Forms.FrmVerzendbrief.objdatasetTekeningen, "Tekeningenbedrijven")

User is offlineProfile CardPM
+Quote Post

sonia.sardana
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 12:04 PM
Post #8

New D.I.C Head
*

Joined: 1 Jun, 2008
Posts: 37

Hello Frnds,I m new to this site..I had posted my Question under Vb.net Forum..But is is shown..how can i ask a question,plz do reply back...
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 12:33 PM
Post #9

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
sonia.sardana it looks like you managed to figure out how to make a new topic. So I am going to assume that you do not need an answer at this point.
User is offlineProfile CardPM
+Quote Post

Hanzie
RE: Updating Tables In Datasets In Other Forms
1 Jun, 2008 - 08:54 PM
Post #10

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 92


My Contributions
Back to my problem.

I believe i have to make an update script for the self made table-adapter which is being filled by a stored procedure.

can anybody tell me if i'm in the right direction?
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Updating Tables In Datasets In Other Forms
2 Jun, 2008 - 07:52 AM
Post #11

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Did clearing the dataset resolve the duplication problem that you were having?
User is offlineProfile CardPM
+Quote Post

Hanzie
RE: Updating Tables In Datasets In Other Forms
2 Jun, 2008 - 09:32 AM
Post #12

D.I.C Head
**

Joined: 19 Aug, 2007
Posts: 92


My Contributions
[Thnx for the reply. Clearing the dataadapter or refresh the datagridview wasn't succsfull.

I believe it is in the update-command? But i'm not sure what to do?!

?? HELP
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:23AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month