Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

I am having a problem. I am using SQL Server as my DB. All is well with loading, adding, deleting data.

Problem is when i insert a record in database:
After inserting a record, it does not show properly in the form unless i close the form and reload it again. Is there any method in VB.net or C# by which we can refresh the table and can load it in the form same time without restarting the form?

thanks:)
Posted
Updated 29-Apr-10 19:27pm
v2

satendra negi wrote:
After inserting a record, it does not show properly in the form unless i close the form and reload it again. Is there any method in VB.net or C# by which we can refresh the table and can load it in the form same time without restarting the form?


Yes, when you modify your data, you need to rebind your form to the data source so that it updates to reflect changes in the database. Set the datasource and databind again.
 
Share this answer
 
The BindingSource[^] Component is your friend.

Particularly the BindingSource.ResetBindings[^] Method.

In addition to that look up BindingSource.ListChanged event on MSDN/Google/Bing/Yahoo. You will find lots of interesting and useful stuff.

Good luck! :)
 
Share this answer
 
You need to set the DataSource to nothing before you try to rebind.
 
Share this answer
 
By the way I got my answer [;)] by myself ..... it was just a line of code [:D]


Thanks yaaro for help
 
Share this answer
 
Comments
Ondeda 27-Aug-10 5:47am    
hi, what was your solution. I seem to be stuck on finding one
Its simple.... what you are doing when your form loads?? write it in one procedure. and call that procedure on form load. When u finish your saving or modifying or deleting data call the same procedure. You dont need to close the form.

Hope this will work.
 
Share this answer
 
WEll thanks all friends for answering and all answers are usefull 10/10


but let me provide some more input ...


i have a function for loading data binding to textboxes etc like
VB
Private Sub filldata()
        Try
            'Dialog2.DataGridView1.DataSource = dBind
            TxtName.DataBindings.Add(New Binding("Text", dspd, "Patient_details.Pname"))
            TxtBedNo.DataBindings.Add(New Binding("Text", dspd, "Patient_details.Pbedno"))
            TxtDr.DataBindings.Add(New Binding("Text", dspd, "Patient_details.pdoc"))
            TxtClass.DataBindings.Add(New Binding("Text", dspd, "Patient_details.pclass"))
            TxtDisease.DataBindings.Add(New Binding("Text", dspd, "Patient_details.pds"))
            TxtDOA.DataBindings.Add(New Binding("Text", dspd, "Patient_details.pdoa"))
            TxtMedicine.DataBindings.Add(New Binding("Text", dspd, "Patient_details.pmd"))
            comboId.DataBindings.Add(New Binding("Text", dspd, "Patient_details.pid"))
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try


but problm is that when i am calling this function again for binding again after inserting data... its showing error that .......

>> System.ArgumentException:this causes two bindings in the collections to bind the same property
:O
 
Share this answer
 

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