auto refresh datagridview ask

magic99

New member
Joined
Aug 12, 2024
Messages
4
Programming Experience
1-3
hello,i need to auto refresh my dgv after any process
i have tried this code but i got errors so help me pls
code.jpg
 
I deleted your duplicate post under the "General C# Discussion".

Please post code as text in code tags, not as screenshots. You can also get the exception text by selecting the text and putting it into the clipboard.
 
C#:
DataTable dtt = new DataTable();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "load_order_sale_all";
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dtt);
            dgvorderSale.DataSource = dtt;
 
I don't know. I usually load lists of objects into my data grid views, rather that data tables.

Doing some searches on the internet, it seems like the common theme for others who encounter the same error is that they sometimes set a DataMember field on the data grid view, but they forget to name the DataTable with that same name.
 
Last edited:
In general, if you move the from code in your Loaded or Visible event handrer (or constructor) that populates the data grid view into a helper method, and then just have your timer Tick event handler also call that same helper method, everything should just work.
 
What is O_S_View? That is explicitly mentioned in the error message yet not at all in any of your posts.

You shouldn't really be creating a new DataTable and rebinding every time. At the very least, just bind one DataTable at the outset and then clear and refill that. Even better would be to not clear it and update it with just new data from the database.
 
What is O_S_View? That is explicitly mentioned in the error message yet not at all in any of your posts.

You shouldn't really be creating a new DataTable and rebinding every time. At the very least, just bind one DataTable at the outset and then clear and refill that. Even better would be to not clear it and update it with just new data from the database.

O_S_View
Just view in db sp call O_S_View
 
Can you show us the SQL for that sproc?

ofcourse


SQL:
ALTER proc [dbo].[load_order_sale_all]
as

SELECT [id] as 'blabla'
      ,[orderdate] as 'blabla'
      ,[valueadd] as 'blabla'
      ,[total] as 'blabla'
      ,[paid] as 'blabla'
      ,[still] as 'blabla'
      ,[nameee] as 'blabla'
      ,[sales] as 'blabla'
      ,[typecustomer] as 'blabla'
      ,[finaldiscount] as 'blabla'
      ,phone as 'blabla'
       ,email as 'blabla'



  FROM O_S_View

O_S_View is view in sql db
 

Latest posts

Back
Top Bottom