Brand new to VB 2008 Express, but have done some work in VB 6. Not sure what I'm missing, but here goes. I have two comboboxes linked to an Access 2007 database. One box lists the names of the States in the US. This is what I used for the Table Adapter Configuration Wizard for the combobox "State"


For the combobox County I used:


ST_UID is an Integer. I created a label with a bound value to STATE.ST_UID so that when a user selects the name of a state from the State box the appropriate ST_UID populates the label, (i.e, California has an ST_UID = 5). The problem is when a state is selected, I only want the Counties for that state to appear in the County box, i.e, COUNTY.ST_UID = 5 if California is the selected state.

I then tried to convert the value in the st_uid label to an integer:
Dim strState As String
Dim StUID As Integer
strState = Val(lblStateName.Text.ToString)
StUID = strState
This is what I last tried when again using the Table Adapter Configuration Wizard for the table that populates the County box:

SELECT ST_UID, CNTY_NAME FROM COUNTY Where ST_UID = 'StUID' Order By st_uid, cnty_name

What I'm getting is a "Data type mismatch in criteria expression."
I'm sure my error is something so simple I'll kick myself when I get this solved, but as I said I'm a beginner so any advice is most appreciated!

7 Years
Discussion Span
Last Post by spider2vb

You need to covert the strState variable to a number when assigning it to StUID, using something like Val() or a .NET method like CInt. One example:

Dim StUID As Integer 
StUID = Val(strState )

Search MSDN for "convert string to number"

How to use Mathematical functions, Type Conversion functions, and String functions in Visual Basic .NET or in Visual Basic 2005
Look at CInt example

You are using a list builder pattern. Find info at ...

List Builders


Thanks jeffryk16. Unfortunately I'm still getting the same error. In VB 6 I would have gotten around this by creating an ADODB parameter, but I didn't think that was necessary in .NET.


filter combobox in a datgrid based on another combobox vb.net
Hi ,,
i have problem with combobox
i have two combobox and two tables

table manages (ManageID, ManageName)
table Departments (DeptID, DeptName, Dept_ManageID)

1- CboEmp_Manage
2- CboEmp_Dept

Public Class Class1

Public sub FillCombobox (ByVal cbo As Combobox, ByVal TableName As String , ByVal Col_name As String , ByVal Col_Value As String , ByVal KKR As String)

Dim VarSql As String
VarSql = ""
VarSql = "Select " + Col_name + " , " + Col_Value + " From " + TableName + " " + KKR
Dim sda As New SqlDataAdapter(VarSql , SQLCon)
Dim ds As New Dataset ()
cbo.DataSource = ds.Tables(0)
cbo.DisplayMember = Col_name
cbo.ValueMember = Col_Value

End Try

End Sub

Private Sub CboEmp_Manage_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboEmp_Manage.SelectedValueChanged

WinClass.FillCombobox (CboEmp_Dept, "Departments WHERE Dept_Manage_ID LIKE '%" & CboEmp_Manage.SelecteIndex.ToString() & "%' " , "Dept_Name", "Dept_ID", "")

End Sub

its work but its give me wrong data from table

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.