| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual Basic .NET Microsoft Visual Basic .NET and related questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
[RESOLVED] Urgent-how to set criteria for SQL query using combobox
Hi all, needed help to set the selection criteria using combobox, but there is a possibility to select "All Items" option. There are more than 2 combobox selection. Really need advise...
Code:
strSQL = "SELECT nama from GridView"
Dim da As New SqlDataAdapter(strSQL, oconnection)
Dim ds As New DataSet
da.Fill(ds, "name")
Dim dt As New DataTable
'dt = ds.Tables(0)
dt.Columns.Add("name", GetType(System.String))
Dim drDSRow As DataRow
Dim drNewRow As DataRow
dt.Rows.Add("*", "All names") ---->just the toppest row that needed the selected value
For Each drDSRow In ds.Tables("name").Rows()
drNewRow = dt.NewRow
drNewRow("name") = drDSRow("name")
dt.Rows.Add(drNewRow)
Next
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
With ComboBox1
.DataSource = dt
.DisplayMember = "nama"
'.SelectedIndex = 0
End With
Last edited by newcoder83; November 1st, 2009 at 11:14 PM. Reason: complete the thread |
|
#2
|
||||
|
||||
|
Re: Urgent-how to set criteria for SQL query using combobox
is this resolved or what ¿
__________________
My Latest Articles : VB and Internet Explorer Browsing History || The TaskBar and VB.NET || Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 Find All My Articles : Here FAQs : .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1 Read This Before You Post || Acceptable Use Policy
|
|
#3
|
|||
|
|||
|
sorry for late respond, i have resolved it. this is the code.
Code:
strSQL1 = " SELECT DISTINCT(ACC) FROM " & Trim(deptGStbl) & " WHERE PT ='" & Trim(cbPT.SelectedValue.ToString) & "'"
If cbPT.SelectedIndex = 0 Then
strSQL1 = strSQL1.Replace("=", " like ")
End If
strSQL2 = " AND KDST ='" & Trim(cbKDST.SelectedValue.ToString) & "'"
If cbKDST.SelectedIndex = 0 Then
strSQL2 = strSQL2.Replace("=", " like ")
End If
strSQL3 = " AND KDKB='" & Trim(cbKDKB.SelectedValue.ToString) & "'"
If cbKDKB.SelectedIndex = 0 Then
strSQL3 = strSQL3.Replace("=", " like ")
End If
strSQL = strSQL1 & strSQL2 & strSQL3
Dim dacbAccGS As New SqlDataAdapter()
dacbAccGS.SelectCommand = New SqlCommand(strSQL, oconnection)
' Create DataSet, fill it and view in data grid
Dim dscbAccGS As New DataSet
dacbAccGS.Fill(dscbAccGS, "acc")
Dim dtcbAccGS As New DataTable
dtcbAccGS.Columns.Add("account", GetType(System.String))
dtcbAccGS.Columns.Add("value", GetType(System.String))
Dim drDSRow As DataRow
Dim drNewRow As DataRow
drNewRow = dtcbAccGS.NewRow
drNewRow("account") = "All Account"
drNewRow("value") = "%"
dtcbAccGS.Rows.Add(drNewRow)
For Each drDSRow In dscbAccGS.Tables("acc").Rows()
drNewRow = dtcbAccGS.NewRow
drNewRow("account") = drDSRow("acc")
drNewRow("value") = drDSRow("acc")
dtcbAccGS.Rows.Add(drNewRow)
Next
cbAccount.DropDownStyle = ComboBoxStyle.DropDownList
With cbAccount
.DataSource = dtcbAccGS
.DisplayMember = "account"
.ValueMember = "value"
'.SelectedIndex = 0
End With
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|