Click here to Skip to main content
15,888,092 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Here is the problem:

I have a datagridview which is binded by datasource using wizard,I am using SQL2005 as the backend.
I am saving the changes in the database and I have a datagridview which shows all the saved records but after I save the changes in database,my datagridview does not show the immediate change.
the connection to Datagridview is via wizard so
VB
 'TODO: This line of code loads data into the 'Equation1DataSet.TotTab' table. You can move, or remove it, as needed.
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)

the above line appears after connection to database.

I have tried
VB
SqlDatagridview1.Refresh()

I have tired the below code which took me 1 step ahead but with problems.
VB
Me.TotTabTableAdapter.Dispose()
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)

The above code refresh's the grid but saves all the enteries in the grid again,I don't understand why.

To solve the saving problem,I also tried with EndEdit function which would indicate end of edit mode
VB
Me.TotTabBindingSource.EndEdit()
Me.TotTabTableAdapter.Dispose()
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)

But still the result is same.

The Saving of all the enteries again is may be because of the line
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)

I have also tried 1 of my friend Jim's answer but still the problem exist
VB
Datagridview1.datasource=nothing
Datagridview1.Datasource=Me.Equation1DataSet

My tries:
VB
Datagridview1.datasource=nothing
Datagridview1.Datasource=Me.Equation1DataSet.TotTab

VB
Datagridview1.datasource=nothing
TotTabTableAdapter.Update(Me.Equation1DataSet.TotTab)
Datagridview1.Datasource=Me.Equation1DataSet.TotTab

The result is still the same.Any thing other than the above mentioned tricks than please suggest.
I though this would be simple but I guess its not.

Please Help..

Thanks in advance.
Posted
Updated 23-Dec-11 19:25pm
v11
Comments
coded007 15-Dec-11 8:38am    
can you post function or code that you are using to bind data grid
Vinay Indoria 15-Dec-11 9:02am    
the connection to Datagridview is via wizard so

'TODO: This line of code loads data into the 'Equation1DataSet.TotTab' table. You can move, or remove it, as needed.
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)

the above line appears after connection to database.

1 solution

You simply need to set the datasource to nothing and then hook it back. That will refresh the datagrid view.
Datagridview1.datasource=nothing
Datagridview1.Datasource=Me.Equation1DataSet.TotTab


This will refresh the datagridview.

I forgot to include the table name. Sorry.. That should work
 
Share this answer
 
v4
Comments
RaviRanjanKr 16-Dec-11 14:59pm    
[Edited]Formatting your code by adding pre tag and code block on your codes[/Edited]
Vinay Indoria 17-Dec-11 1:08am    
Thanks for your Answer but it doesn't work.
The grid goes blank
Jim Fallin 17-Dec-11 13:48pm    
I changed the solution to put the table name on blankthe end of the dataset name. Just the dataset would make the view go .blank. It should work now
Vinay Indoria 18-Dec-11 23:17pm    
Ya I understood that you forgot the table name,I did that by myself,means I added the table name,you can see the question I have put my tries in the question.
It didn't work.
Thanks alot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900