Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 793
  • 1.1k
  • 53.7k

Sql Data Reader does not contain the definition of Item

May 25 2024 10:34 AM

Hello Team,

Am trying to load data in the textbox but is like my formart is not working

 private void btn_Search_Click(object sender, EventArgs e)
        {
            int i = 0;
            dataGridView1.Rows.Clear();
            cn.Open();
            cm = new SqlCommand("select PCode,ProductDate, ProductName,Category,CostPrice,Profit,SalesPrice, Tax,TotalPrice,Barcode from tblProduct where PCode like '%" + txt_SearchProduct.Text + "%'", cn);
            dr = cm.ExecuteReader();
            while (dr.Read())
            {

                txt_ProductCode.Text = dr.Item("PCode");
                dtProductDate.Text = dr.Item("ProductDate");
                txt_Productname.Text = dr.Item("ProductName");
                cbo_Category.SelectedValue = dr.Item("Category");
                txt_CostPrice.Text = dr.Item("CostPrice");
                txt_SalesPrice.Text = dr.Item("SalesPrice");               
                cbo_Tax.SelectedValue = dr.Item("Tax");
                txt_TotalPrice.Text = dr.Item("TotalPrice");                
                txt_Barcode.Text = dr.Item("Barcode");
                dr.Close();
                cn.Close();
            }

        }

 


Answers (4)