Naeem Khan

Naeem Khan

  • 895
  • 782
  • 790.3k

How to fill datagridview row by row in c# using barcode

Jul 20 2015 4:23 AM
Hi,

I have a windows application developed in c#.
I have datagridview with three columns in it.
I will be scanning barcode in the text box.After scanning a particular barcode, i need to query the database and fill the barcodes info in the datagridview columns of the current row.
Like wise after scanning each barcode i need to fill the particular row like above.

i used this kind of code but its not working ..
 
try
{
MySqlConnection con = new MySqlConnection(StartUp.database);
con.Open();
MySqlCommand cmd = new MySqlCommand("select Accession_no,Title_in_full from t_book_details where Accession_no ='" + txt_accession_no.Text + "'", con);
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
gv_show_details.Rows[0].Cells[0].Value = dr[0].ToString();
gv_show_details.Rows[0].Cells[1].Value = dr[1].ToString();
gv_show_details.Rows.Add(dr);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
 please give me idea where i m doing mistakes..
 
thanks in advance

Answers (4)