i want to know how to retrieve data in datagridview fast from mssql. like when i run my program my grid starts with filling the data and it's quite slowly like i can see the filling process it's just take 2 seconds but i want it to do fast like in nano seconds . anyone let me know how to do this. by the way it's desktop application develop on C# and project is barcode based point of sale system
private void FillGrid() {
DataTable xTable = new DataTable();
new SqlDataAdapter("select * from tblProducts order by BID DESC",xConn).Fill(xTable);
DGV1.DataSource = xTable;
DGV1.Columns[0].Width = 50;
DGV1.Columns[1].Width = 100;
DGV1.Columns[2].Width = 150;
DGV1.Columns[3].Width = 50;
for (int i = 0; i < DGV1.Rows.Count-1; i++)
{
int QTY = Int32.Parse(DGV1.Rows[i].Cells[4].Value.ToString());
if(QTY >=21 && QTY <= 50)
{
DGV1.Rows[i].Cells[4].Style.BackColor = Color.Yellow;
DGV1.Rows[i].Cells[4].Style.Font = new Font("Arial", 11, FontStyle.Bold);
}
else if (QTY >= 0 && QTY <= 20)
{ DGV1.Rows[i].Cells[4].Style.BackColor = Color.Red;
DGV1.Rows[i].Cells[4].Style.Font = new Font("Arial", 11, FontStyle.Bold);
}
{ DGV1.Rows[i].Cells[4].Style.BackColor = Color.Green;
DGV1.Rows[i].Cells[4].Style.Font = new Font("Arial", 11, FontStyle.Bold);
}
}
}
As far as i know, stored procedure are faster than the function, use them ! furthermore if you can share the code or some scenario details, so i can easily solve your problem.