Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hai experts,

I am doing a windows application.
I have a form to add user details on clicking the save button the user details will be added to database.I have a datagridview in another form to bind the user details which is added by the first form.But my binding is not working properly

The problem is when i click save button the grid is not binding.But if i Close the application and open it the grid will bind

my code to bind grid

public void BindEmployeeGrid()
{

DataTable dt = dalObj.GetUserDetails();
gvUserDetails.AutoGenerateColumns = false;
gvUserDetails.DataSource = dt;
}
Posted
Comments
SRK90 7-Aug-14 4:53am    
did you use gvUserDetails.Databind(); after giving data source to grid view ?
HK33 7-Aug-14 5:06am    
we cant give gvYserDetails.Databind() in windows forms ryt.????
i dont see an option for that..
its applicable only in asp.net web forms i guess
TrushnaK 7-Aug-14 7:35am    
have you called BindEmployeeGrid() this method on button click ?

1.The problem is that your "data object" is loading the data at the begging, than will cache the data and the grid will be bind with this cached data.

2.So when the user will add/modify/delete data you have to refresh your "data object" to reload the data from the database, then the grid will show the updated data.
 
Share this answer
 
Comments
HK33 7-Aug-14 5:10am    
sir
on clicking the button save i am calling the form in which grid is bind.
on the initializing method i have called the method to bind the grid..



Code on Initialize page is like this

public EmployeeDetails()
{

InitializeComponent();
BindEmployeeGrid();

}
on clickong save i am opening this form so automatically the bind function will be called ryt.?

code on save

if (res)
{
MessageBox.Show("Inserted Succesfully", "My Application",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
EmployeeDetails obj = new EmployeeDetails();
Raul Iloc 7-Aug-14 6:19am    
Like I said in my solution above, the problem is in your "data object", and not in the other part. Check the method "dalObj.GetUserDetails()" and make shore that it will load the data from the database, not from the cache, because could be the situation that you are sharing the same "data object" in all UI part, and you must force it to load the data from DB.
HK33 8-Aug-14 2:46am    
public DataTable GetUserDetails()
{
DataTable dt = new DataTable();
SqlCeConnection con = GetConnection();
try
{
con.Open();
string query = "select UserID,FirstName,LastName,Email,ContactNumber,Location,Department from UserDetails where Status='A'";
//SqlCeCommand cmd = new SqlCeCommand(query, con);
SqlCeDataAdapter daObj = new SqlCeDataAdapter(query, con);
daObj.Fill(dt);
return dt;
}
finally
{
con.Close();
}
this is the function GetUserDetails
this is taking values direcctly from database ryt.?

I dont know any other method
Raul Iloc 8-Aug-14 2:49am    
Yes, this code is OK and is reading directly the data from the database.
So the only place that could generate the problem is the code that save the changes into your database. Maybe there the new added data are cached!?
HK33 8-Aug-14 4:21am    
is there any solution for that..Actualy i didnt know about these cache..
How to check wether it is cached or not ..
Thanks for your support .
Hi, please try this:

Please use gvUserDetails.DataBind(); at the end.

public void BindEmployeeGrid()
{

DataTable dt = dalObj.GetUserDetails();
gvUserDetails.AutoGenerateColumns = false;
gvUserDetails.DataSource = dt;
gvUserDetails.DataBind();
}

Hope this will solve your problem.
 
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