hi...... projot here
I am facing a problem in the code
i have to populate the combo box from datagrid view from database
just help me in doing it this code is giving me an error
my contact no is 9049776416
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class supplier_update
Dim con1 As MySqlConnection
Dim con2 As MySqlConnection
Dim con3 As MySqlConnection
Dim con4 As MySqlConnection
Dim cm As MySqlCommand
Dim cmm As MySqlCommand
Dim cmmm As MySqlCommand
Dim adpt As New MySqlDataAdapter
Dim ds As New DataSet
Dim a As Integer
Dim j As Integer = 0
Dim ca As String = ""
Dim cq As String = ""
Dim billno As Integer
Dim r_name As String
Dim d, t As Integer
Dim h As Integer = 0
Dim cs As String = "cash"
Dim i As Integer = -1
Dim va As Integer = 0
Private Sub supplier_update_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
con1 = New MySqlConnection("database=liberty_datbase;data source=localhost;user id=root;password=82684")
con2 = New MySqlConnection("database=liberty_datbase;data source=localhost;user id=root;password=82684")
con3 = New MySqlConnection("database=liberty_datbase;data source=localhost;user id=root;password=82684")
con4 = New MySqlConnection("database=liberty_datbase;data source=localhost;user id=root;password=82684")
loadData()
cal1()
Catch ex As Exception
MessageBox.Show("unable to connect to the database" & ex.ToString(), "supplier", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop)
End Try
End Sub
Sub cal1()
con2.Open()
Dim dr As MySqlDataReader
categoryDataGridViewComboBoxColumn.Items.Clear()
cm = New MySqlCommand("select distinct(category) from inventory", con2)
cm.CommandType = CommandType.Text
dr = cm.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
While dr.Read
'If Not IsDBNull(dr.Item("category")) Then
categoryDataGridViewComboBoxColumn.Items.Add(dr.Item("category"))
' End If
End While
End If
dr.Close()
End Sub
Sub c()
Try
cal1()
If sup_gv.Rows(j).Cells(0).Selected = True Then
sup_gv.Rows(j).Cells(0).ReadOnly = True
con3.Open()
Dim dr1 As MySqlDataReader
item_name.Items.Clear()
cm = New MySqlCommand("select item_name from inventory where category='" & sup_gv.Rows(j).Cells(0).Value() & "'", con3)
MessageBox.Show("select item_name from inventory where category='" & sup_gv.Rows(j).Cells(0).Value() & "'")
cm.CommandType = CommandType.Text
dr1 = cm.ExecuteReader(CommandBehavior.CloseConnection)
If dr1.HasRows Then
While dr1.Read
If Not IsDBNull(dr1.Item("item_name")) Then
item_name.Items.Add(dr1.Item("item_name"))
End If
End While
End If
va = va + 1
j = j + 1
dr1.Close()
Else
MessageBox.Show("errrorrrrr")
End If
Catch ex As Exception
MessageBox.Show("error")
End Try
End Sub
Sub loadData()
con1.Open()
Try
adpt = New MySqlDataAdapter()
cm = New MySqlCommand()
ds = New DataSet()
cm.CommandText = "select * from supplier"
cm.Connection = con1
adpt.SelectCommand = cm
adpt.Fill(ds, "supplier")
Catch ex As Exception
MessageBox.Show("unable to load data" & ex.ToString(), "supplier", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop)
End Try
con1.Close()
End Sub
Private Sub sup_gv_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles sup_gv.CellLeave
Dim retailer_price, r, cons As Integer
Dim total As Integer = 0
For va As Integer = 0 To sup_gv.RowCount - 2
MessageBox.Show("val" & va)
Dim rate, qty, cal As Integer
rate = sup_gv.Rows(va).Cells(3).Value()
qty = sup_gv.Rows(va).Cells(2).Value()
cons = sup_gv.Rows(va).Cells(4).Value()
cal = rate * qty
sup_gv.Rows(va).Cells(6).Value() = cal
r = (cons - rate) * 0.5
retailer_price = r + rate
sup_gv.Rows(va).Cells(5).Value() = retailer_price
total = total + sup_gv.Rows(va).Cells(6).Value()
gt.Text = total
Next va
c()
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
Dim a = RadioButton1.Checked
If (a = False) Then
cheque_txt.Visible = False
Label5.Visible = False
Else
cheque_txt.Visible = True
Label5.Visible = True
End If
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles back.Click
Me.Hide()
mainmenu.Show()
End Sub
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click
name_txt.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = True
cheque_txt.Text = ""
sup_gv.Rows.Clear()
gt.Text = ""
End Sub
Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
con4.Open()
Try
If name_txt.Text = "" Then
MsgBox("Enter the name", MsgBoxStyle.Information, "verify")
ElseIf cheque_txt.Text = "" Then
MsgBox("Enter the cheque no", MsgBoxStyle.Information, "verify")
Else
Dim sst As String
sst = "select max(bill_no) from supplier"
ds = New DataSet()
adpt = New MySqlDataAdapter(sst, con4)
adpt.Fill(ds)
If IsDBNull(ds.Tables(0).Rows(0).Item(0)) Then
d = 1
Else
d = ds.Tables(0).Rows(0).Item(0) + 1
End If
bill_no.Text = d
r_name = name_txt.Text.Trim
For i As Integer = 0 To sup_gv.RowCount - 2
Dim st As String
st = "select max(trans_no) from supplier"
ds = New DataSet()
adpt = New MySqlDataAdapter(st, con4)
adpt.Fill(ds)
If IsDBNull(ds.Tables(0).Rows(0).Item(0)) Then
t = 1
Else
t = ds.Tables(0).Rows(0).Item(0) + 1
End If
MessageBox.Show("insert into supplier values(" & t & "," & d & ",'" & r_name & "','" & sup_gv.Rows(i).Cells(0).Value() & "','" & sup_gv.Rows(i).Cells(1).Value() & "'," & sup_gv.Rows(i).Cells(2).Value() & "," & sup_gv.Rows(i).Cells(3).Value() & "," & sup_gv.Rows(i).Cells(4).Value() & "," & sup_gv.Rows(i).Cells(5).Value() & "," & sup_gv.Rows(i).Cells(6).Value() & "," & gt.Text & ",'" & cheque_txt.Text & "','" & txt_date.Text & "')")
cm.CommandText = "insert into supplier values(" & t & "," & d & ",'" & r_name & "','" & sup_gv.Rows(i).Cells(0).Value() & "','" & sup_gv.Rows(i).Cells(1).Value() & "'," & sup_gv.Rows(i).Cells(2).Value() & "," & sup_gv.Rows(i).Cells(3).Value() & "," & sup_gv.Rows(i).Cells(4).Value() & "," & sup_gv.Rows(i).Cells(5).Value() & "," & sup_gv.Rows(i).Cells(6).Value() & "," & gt.Text & ",'" & cs & "','" & cheque_txt.Text & "','" & txt_date.Text & "')"category.Selected() & "','" & item_name.Selected() & "'," & sup_gv.Rows(i).Cells(2).Value() & "," & sup_gv.Rows(i).Cells(3).Value() & "," & sup_gv.Rows(i).Cells(4).Value() & "," & sup_gv.Rows(i).Cells(5).Value() & "," & gt.Text & ",'" & cheque_txt.Text & "','" & txt_date.Text & "')"
cm.Connection = con4
cm.ExecuteNonQuery()
Next i
MsgBox("data is stored")
loadData()
End If
con4.Close()
Catch ex As Exception
MsgBox("Error:Inserting data")
End Try
End Sub
Private Sub sup_gv_RowLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles sup_gv.RowLeave
va = va + 1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each row As DataGridViewRow In sup_gv.SelectedRows
sup_gv.Rows.Remove(row)
Next
End Sub
End Class