-
June 26th, 2014, 02:51 PM
#1
How to Select statement using the value from Combobox in the form of VB.net
Hi
i m a new to VB.net. I'm trying to show the different form of DataGrid View based on the value from Combobox. The problem is the data from Combobox and Datagrid view are from different tables.
I have form1, form2 and form3
Here is some of my code from form2
I would like to write the select statement matching the value from Fr2ComBo in ea00 table and show the result in form3 with datagrid view.
Could someone please help me???
Thank you in advance.
Public Class Form2
Private Property Avail3 As BindingSource
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'AvailgrpDataSet.arctm' table. You can move, or remove it, as needed.
Me.ArctmTableAdapter.Fill(Me.AvailgrpDataSet.arctm)
Dim connetionString As String
Dim connection As OleDbConnection
Dim oledbAdapter As OleDbDataAdapter
Dim ds As New DataSet
Dim sql As String
''Dim i As Integer
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\visual basic\availgrp.mdb;"
sql = "select reptrc + ' ' + desc as reptrcdesc From arctm "
connection = New OleDbConnection(connetionString)
Try
connection.Open()
oledbAdapter = New OleDbDataAdapter(sql, connection)
oledbAdapter.Fill(ds) 'fill the datatable from the SQL and the dataSet
oledbAdapter.Dispose()
connection.Close()
'TODO: This line of code loads data into the 'AvailgrpDataSet.arctm' table. You can move, or remove it, as needed.
'' Me.ArctmTableAdapter.Fill(Me.AvailgrpDataSet.arctm)
Fr2ComBo.DataSource = ds.Tables(0)
Fr2ComBo.DisplayMember = "reptrcdesc"
Catch ex As Exception
MessageBox.Show("Can not open connection ! ")
End Try
End Sub
*** that's where my problem start
Private Sub ButCnt_Click(sender As System.Object, e As System.EventArgs) Handles ButCnt.Click
Dim connetionStrings As String
Dim connection As OleDbConnection
Dim oledbAdapter As OleDbDataAdapter
Dim ds As New DataSet
Dim sql As String
Avail3 = New BindingSource(ds, "ea00")
' ' how to filter and show the result in form3.????
sql = " select * from ea00 where reptrc=Fr2ComBo.text"
Form3.show()
End Sub
-
June 27th, 2014, 12:36 AM
#2
Re: How to Select statement using the value from Combobox in the form of VB.net
Did you try they TODO's? Uncomment one just for fun!
-
June 27th, 2014, 01:10 AM
#3
Re: How to Select statement using the value from Combobox in the form of VB.net
Code:
sql = " select * from ea00 where reptrc=Fr2ComBo.text"
Since that is all in quotes it would be looking for the literal text " Fr2ComBo.text"
You need to build the string so that it gets the value of the combobox
Code:
sql = " select * from ea00 where reptrc=" & Fr2ComBo.text
Note that if this is a text field then you also need to use single quotes around that value, if it is a date field then you may need to use single quotes around it or you may need to use the # symbol around it depending on the database in use
Always use [code][/code] tags when posting code.
-
June 27th, 2014, 02:13 PM
#4
Re: How to Select statement using the value from Combobox in the form of VB.net
Originally Posted by DataMiser
Code:
sql = " select * from ea00 where reptrc=Fr2ComBo.text"
Since that is all in quotes it would be looking for the literal text " Fr2ComBo.text"
You need to build the string so that it gets the value of the combobox
Code:
sql = " select * from ea00 where reptrc=" & Fr2ComBo.text
Note that if this is a text field then you also need to use single quotes around that value, if it is a date field then you may need to use single quotes around it or you may need to use the # symbol around it depending on the database in use
Thank you, this sql works well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|