Rishad Hasan
Member
- Joined
- Feb 1, 2013
- Messages
- 8
- Programming Experience
- Beginner
Hello All,
I am kind a new in vb.net. I have a combobox where I have two choices and for those two choices I have data stored in two different fields in the same access database table. I was wondering what code should I write to pick the right part from database table according to user's pick from combobox. I am here attaching what I got from me. Would you mind suggest me where should I correct in this code.
Thanks.
Private Sub findPartNumberforItem15()
Dim Table_ As String
Table_ =
"Item_15"
Dim query As String = "SELECT * FROM " & Table_
Dim MDBConnString_ As String = dataBaseLocation
Dim ds As New DataSet
Dim cnn As OleDb.OleDbConnection = New OleDb.OleDbConnection(MDBConnString_)
cnn.Open()
Dim cmd As New OleDb.OleDbCommand(query, cnn)
Dim da As New OleDb.OleDbDataAdapter(cmd)
da.Fill(ds, Table_)
cnn.Close()
Dim t1 As DataTable = ds.Tables(Table_)
'Dim row As DataRow
Dim i As Integer
For i = 0 To 3
MsgBox(i)
MsgBox(
"*" + t1.Rows(i).Item("Size") + "*")
MsgBox(
"*" + ComboBox4.Text + "*")
If ComboBoxInletPressure.SelectedIndex = 0 Then
Table_ =
"Item_15"
ElseIf t1.Rows(i).Item("Size") = ComboBox4.Text Then
If Not IsDBNull(t1.Rows(i).Item("0_5PSI")) Then
partNumber = t1.Rows(i).Item(
"0_5PSI")
ElseIf Not IsDBNull(t1.Rows(i).Item("6_25PSI")) Then
partNumber = t1.Rows(i).Item(
"6_25PSI")
End If
Exit For
End If
Next i
End Sub
I am kind a new in vb.net. I have a combobox where I have two choices and for those two choices I have data stored in two different fields in the same access database table. I was wondering what code should I write to pick the right part from database table according to user's pick from combobox. I am here attaching what I got from me. Would you mind suggest me where should I correct in this code.
Thanks.
Private Sub findPartNumberforItem15()
Dim Table_ As String
Table_ =
"Item_15"
Dim query As String = "SELECT * FROM " & Table_
Dim MDBConnString_ As String = dataBaseLocation
Dim ds As New DataSet
Dim cnn As OleDb.OleDbConnection = New OleDb.OleDbConnection(MDBConnString_)
cnn.Open()
Dim cmd As New OleDb.OleDbCommand(query, cnn)
Dim da As New OleDb.OleDbDataAdapter(cmd)
da.Fill(ds, Table_)
cnn.Close()
Dim t1 As DataTable = ds.Tables(Table_)
'Dim row As DataRow
Dim i As Integer
For i = 0 To 3
MsgBox(i)
MsgBox(
"*" + t1.Rows(i).Item("Size") + "*")
MsgBox(
"*" + ComboBox4.Text + "*")
If ComboBoxInletPressure.SelectedIndex = 0 Then
Table_ =
"Item_15"
ElseIf t1.Rows(i).Item("Size") = ComboBox4.Text Then
If Not IsDBNull(t1.Rows(i).Item("0_5PSI")) Then
partNumber = t1.Rows(i).Item(
"0_5PSI")
ElseIf Not IsDBNull(t1.Rows(i).Item("6_25PSI")) Then
partNumber = t1.Rows(i).Item(
"6_25PSI")
End If
Exit For
End If
Next i
End Sub