Click here to Skip to main content
15,886,065 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi

I'm using windows form & I have a dgv on my form that I fill it menualy and I use linq to sql in my project(c# project) but when I execute my update_sp and fill the dgv again, my dgv isn't updated and I should close the dgv container form and reopen it to see my updated tbl ...

What can I do for solving this problem?

my sp_update calling codes:

C#
DataClassesDataContext dc = new DataClassesDataContext();
dc.sp_tblbooks_update(radif, txttitle.Text, txtauthor.Text, txttranslator.Text, txtsubject.Text, txtpublicator.Text, txtpublicatonyear.Text, bool.Parse(cmbavailable.Text), txtdescription.Text);
dc.SubmitChanges();
this.Close();

and when my form is closed,I call a linq select command to get data from db and refill the dg:
C#
var showbooksquery =
               from books in db.tblbooks
               select books;
           dataGridView1.DataSource = showbooksquery;


Note* select(search) & insert command work properly but update doesn't..
I think it is because of locking the table when an operation is running... but I don't know how to deal with this problem...
plzz help
Posted
Updated 27-Aug-14 12:33pm
v4

You don't show the code where you refresh the dgv after the update is commited, so I'm assuming you didn't do that?
 
Share this answer
 
Comments
xfull-f 27-Aug-14 18:16pm    
Excuse me ... I'm using win form and I have refreshed my dgv but it had no effect...
& I fill the dgv menualy
Dave Kreskowiak 27-Aug-14 19:03pm    
I asked for the code, not your opinion of what you think you did. It doesn't work because wheat the machine expects and what you THINK you did are two different things.
xfull-f 27-Aug-14 19:44pm    
I have written all the essential codes and other codes are in Linq to SQL classes and I didn't change them but as u might have realized I use 2 forms one for editing and other for showing datas and I call the editfrm from showfrm as showdialog and when update code finishes and the form is closed a Linq query get the data and fill the dgv as I have written the codes...thank u for ur responsibility
The solution depends of the front end that you are using. Are you using windows forms, web, console or etc?
If you are using web, in that case ASP.NET, you will need to refresh the page after fill the dtg. You can also use a dynamic control as Jquery or Ajax to update only the dtg.
 
Share this answer
 
Comments
xfull-f 27-Aug-14 19:50pm    
I use win form
ClaudioBalbin 27-Aug-14 20:20pm    
Then you'll need to generate an event to update your dgt. You can do that with a simple timer for example.
One thing to keep in mind is that a table update in the database is not enough to make your dgt update itself. They are disconnected events.
In a more sofisticated approach, you could program a listener (thread) to update the dgt if something changes in the table.
xfull-f 28-Aug-14 6:12am    
Thank for ur reply but I fill the dgv with linq query after updating the table...is it not enough?
ClaudioBalbin 28-Aug-14 8:15am    
If it is after updating the table it should work, but to gave a proper solution we will need to see this part of your code.
Hi guys thank u for ur answers I should make a new instance of dbdatacontext before showquery...
 
Share this answer
 
Comments
Dave Kreskowiak 28-Aug-14 16:32pm    
This is why I was stressing showing us the code, not your opinion of what's going on.

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