I wanted to fill a datagridview from database, the datagridview has colums Product,Qty,Price,Total,Description
The Product Column is a Combobox in which I want product_name as displayMember and product_id as ValueMember but the select sholud be according to the query.
I tried the below but its not working, I want this for update, as if the user wants to change the product or qty etc.
Thanks in advance.
Sorry if I did clearly described what I wanted to do becoz of my English, then I try to explain it once again.
I have mysql tables
product have fields product_id,product_name
dailysale have fields product_id,qty,price,total,description
I have a datagridview with having columns 1. Product, 2. Qty, 3. Price, 4. Total 5. Desc, and 6. billno
Table dailysale can retrieve product_name based on product_id
The Product Columns is a ComboBox in which the Display member is product_name and the value member is product_id, I save product_id in dailysale.
Now What I want is to that When a user wanted to edit any sale order, He enter a billno and the bill retrieves into the datagridview where I dont know how to retrieve the products in the combobox cell.
I tried the above code but in the below line it say object reference is not set to an instance of an object
What I have tried:
sql = "SELECT product.product_name,dailysale.product_id,dailysale.qty, dailysale.price, dailysale.total, dailysale.description FROM dailysale INNER JOIN product ON product.ID = dailysale.product_id WHERE billno ='" & txtbillno.Text & "'"
cmd = new MysqlCommand(sql,conn)
dr = cmd.excmd = New MySqlCommand(sqL, conn)
dr = cmd.ExecuteReader
dim i as Integer = 0
Do While dr.Read = True
Dim dgvcc As New DataGridViewComboBoxCell
dgvcc = DirectCast(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1), DataGridViewComboBoxCell)
Dim dt As DataTable = New DataTable
.DataSource = dt
.ValueMember = "product_id"
.DisplayMember = "product_name"
.Selected = ""
DataGridView1.Rows.Add(i, dgvcc.Value, dr("qty"), dr("price"), dr("total"), dr("description"))
y += 17
DataGridView1.Height += y