Rishad Hasan
Member
- Joined
- Feb 1, 2013
- Messages
- 8
- Programming Experience
- Beginner
Hello Everyone,
I am a beginner with vb.net. My database got two tables named "Housing" and "Head". My target is to pull the right part number from tables and show in the output csv format when I'll select everything in my windows application form comboboxes and textboxes. I already did for Housing table but I am wondering how can I pull the partnumber for "Head" under the same button click. So, bottom line is after my all selection in windows application form, I'll hit "output" button and it'll bring right part numbers for both tables in csv file. Please, look at my code attachment.If u suggest then, it'll be a great help for me. Thanks
I am a beginner with vb.net. My database got two tables named "Housing" and "Head". My target is to pull the right part number from tables and show in the output csv format when I'll select everything in my windows application form comboboxes and textboxes. I already did for Housing table but I am wondering how can I pull the partnumber for "Head" under the same button click. So, bottom line is after my all selection in windows application form, I'll hit "output" button and it'll bring right part numbers for both tables in csv file. Please, look at my code attachment.If u suggest then, it'll be a great help for me. Thanks
Private Sub ButtonOutputCSV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOutputCSV.Click out = My.Computer.FileSystem.OpenTextFileWriter(file, False) Dim op As Integer Dim con As New OleDb.OleDbConnection Dim dbProvider As String Dim dbSource As String Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String dbProvider = "Provider=Microsoft.ace.oledb.12.0;" dbSource = "Data Source=U:\TRatul\JB3 Configurator\JB3.accdb" con.ConnectionString = dbProvider & dbSource con.Open() sql = "SELECT*FROM Housing" da =New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "Housing") con.Close() Dim t1 As DataTable = ds.Tables("Housing") Dim i As Integer For i = 0 To 1 If Not IsDBNull(t1.Rows(i).Item("Housing_PN")) Then findPartNumberforHousing() op = 10 If partNumber <> "0" Then WR(partNumber, 1, op, "Housing") End If Exit For Next i out.Close() Shell("notepad C:\Webster\Test.txt") End Sub Private Sub WR(ByVal data1 As String, ByVal data2 As Integer, ByVal data3 As Integer, ByVal data4 As String) Dim Debugflag As Boolean Debugflag = True 'this can be turned on and off If Debugflag = True Then ot.WriteLine(data1 + "," + Str(data2) + "," + Str(data3) + "," + data4) Else out.WriteLine(data1 + "," + Str(data2) + "," + Str(data3)) End If End Sub Private Sub findPartNumberforHousing() Dim con As New OleDb.OleDbConnection Dim dbProvider As String Dim dbSource As String Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String = "SELECT*FROM Housing" dbProvider = "Provider=Microsoft.ace.oledb.12.0;" dbSource = "Data Source=U:\TRatul\JB3 Configurator\JB3.accdb" con.ConnectionString = dbProvider & dbSource con.Open() da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "Housing") con.Close() Dim t1 As DataTable = ds.Tables("Housing") Dim i As Integer For i = 0 To 1 'MsgBox(i) If t1.Rows(i).Item("Orientation") = ComboBoxOrientation.Text Then If Not IsDBNull(t1.Rows(i).Item("Housing_PN")) Then partNumber = t1.Rows(i).Item( "Housing_PN") Else partNumber = 0 End If Exit For End If Next i End Sub Private Sub findPartNumberforHead() Dim con As New OleDb.OleDbConnection Dim dbProvider As String Dim dbSource As String Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String dbProvider = "Provider=Microsoft.ace.oledb.12.0;" dbSource = "Data Source=U:\TRatul\JB3 Configurator\JB3.accdb" con.ConnectionString = dbProvider & dbSource con.Open() sql = "SELECT*FROM Head" da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "Head") con.Close() Dim t1 As DataTable = ds.Tables("Head") Dim i As Integer For i = 0 To 7 'MsgBox(i) If t1.Rows(i).Item("Fuel") = ComboBoxFuel.Text Then If TextBoxInputMBH.Text <= 6300 And TextBoxNoseLength.Text = 4 Then If Not IsDBNull(t1.Rows(i).Item("Lo_Input")) Then partNumber = t1.Rows(i).Item("Lo_Input") Else partNumber = 0 End If ElseIf TextBoxInputMBH.Text > 6300 And TextBoxNoseLength.Text = 4 Then If Not IsDBNull(t1.Rows(i).Item("Hi_Input")) Then partNumber = t1.Rows(i).Item("Hi_Input") Else partNumber = 0 End If ElseIf TextBoxInputMBH.Text > 6300 And TextBoxNoseLength.Text > 4 Then If Not IsDBNull(t1.Rows(i).Item("Hi_Input_Dash")) Then partNumber = t1.Rows(i).Item("Hi_Input_Dash") Else partNumber = 0 End If End If Exit For End If Next i End Sub End Class