Private Sub FillCasteCol()
Dim con As OdbcConnection = New OdbcConnection
For Each row As DataGridViewRow In dgvUserDetails.Rows
If row.Index < dgvUserDetails.Rows.Count - 1 Then
Dim cmbcell As New DataGridViewComboBoxCell
dgvUserDetails.Rows(row.Index).Cells(7) = cmbcell
sql = "Select caste from datafile where Part_No = " & dgvUserDetails.Item("Part_No", row.Index).Value & " and SLNOINPART = " & dgvUserDetails.Item("SLNOINPART", row.Index).Value & " and fullname = '" & dgvUserDetails.Item("Name", row.Index).Value & "'"
If rs.State = 1 Then rs.Close()
rs.Open(sql, MainCon, 1, 3)
If Not rs.EOF And Not IsDBNull(rs.Fields(0).Value) Then
gCaste = rs.Fields(0).Value
cmbcell.Value = gCaste
sql = "Select Description from Category where Catgry = 1 and Description <> '" & gCaste & "'"
con.ConnectionString = connstring
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, con)
If ds.Tables.Contains("Caste") Then
If ds.Tables("Caste").Rows.Count > 0 Then
ds.Tables("Caste").Rows.Clear()
End If
End If
da.Fill(ds, "Caste")
cmbcell.Items.Add(gCaste)
cmbcell.DataSource = ds.Tables("Caste")
cmbcell.DisplayMember = ds.Tables("Caste").Columns(0).ColumnName.ToString
con.Close()
Else
sql = "Select Description from Category where Catgry = 1"
con.ConnectionString = connstring
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, con)
If ds.Tables.Contains("Caste") Then
If ds.Tables("Caste").Rows.Count > 0 Then
ds.Tables("Caste").Rows.Clear()
End If
End If
da.Fill(ds, "Caste")
cmbcell.DataSource = ds.Tables("Caste")
cmbcell.DisplayMember = ds.Tables("Caste").Columns(0).ColumnName.ToString
End If
End If
con.Close()
Next
End Sub