Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating windows application using c# 2010, here I am using data grid view for billing purpose,  how to add next and previous button for data grid view, I want records view by customer wise one by one records.  Any one give me some ideas.


What I have tried:

<pre>	I am creating windows application using c# 2010, here I am using data grid view for billing purpose,  how to add next and previous button for data grid view, I want records view by customer wise one by one records.  Any one give me some ideas.
Posted
Updated 17-Apr-20 1:58am
Comments
Ralf Meier 17-Apr-20 7:20am    
OK ... where do you stuck ...?
Boopalslm 17-Apr-20 7:27am    
I am use this below code, i am click a button all records are display in my data grid view,

SqlConnection con=new SqlConnection(db.Connectionstring());
DataSet ds = new DataSet();
try
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM sales where cstname='"+txtFind.Text+"'", con);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];

dataGridView1.DataMember = "sales";

}
catch (Exception ex)
{
//Exception Message
}
finally
{
con.Close();
con.Dispose();
}


how to solve this problem.

1 solution

Firstly, your sql command is at risk of SQL Injection attack. Never use concatenated strings to construct your sql - use parameters
SQL Injection | OWASP[^]
SQL Injection Prevention · OWASP Cheat Sheet Series[^]

To address your actual question - you need to "page" your results so that you only query for the rows you want to display. The following example is for ASP but the principle is universal How to implement Paging in ASP.NET at SQL Query Level[^]
 
Share this answer
 
Comments
CHill60 18-Apr-20 8:27am    
Thanks a bunch. If you have a better solution then why not post it?
BillWoodruff 19-Apr-20 1:25am    
+5

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