Hoping someone can help me and tell me what I am doing wrong...
I have a dataset that has a table in it called zipcodes. Declared it this way...
' Create a new DataTable and set a DataColumn object as the primary key.
dsInfoServices.Tables.Add("ZipCode")
Dim keys(1) As DataColumn
Dim myColumn As DataColumn
' Create column 1 and add it to the array.
myColumn = New DataColumn
myColumn.DataType = System.Type.GetType("System.String")
myColumn.ColumnName = "ZipCode"
dsInfoServices.Tables("ZipCode").Columns.Add(myColumn)
' Add the column to the array.
keys(0) = myColumn
' Set the PrimaryKeys property to the array.
dsInfoServices.Tables("ZipCode").PrimaryKey = keys
sqlCmdServices.CommandText = "spGetZipCodes"
sqlAdapterServices.Fill(dsInfoServices, "ZipCodes")
Then I am trying to autofill a text field once they change it so I do the following:
Private Sub txt_ServiceZip_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_ServiceZip.TextChanged
Dim sSQL As String
sSQL = "Zipcode Like '" & Me.txt_ServiceZip.Text & "%'"
Dim rows() As DataRow = dsInfoServices.Tables("ZipCode").Select(sSQL)
If (Not rows.Length > 0) Then
Dim iLength As Integer
iLength = Len(Me.txt_ServiceZip.Text)
Me.cmb_ServiceState.SelectedValue = rows(0).Item("StateID")
sqlCmdServices.CommandText = "spGetCities '" & Me.txt_ServiceZip.Text & "'"
sqlAdapterServices.Fill(dsInfoServices, "Cities")
Me.txt_ServiceZip.Text = rows(0).Item("ZipCode")
Me.txt_ServiceZip.SelectionStart = iLength
Me.txt_ServiceZip.SelectionLength = Len(rows(0).Item("ZipCode"))
End If
End Sub
----------------------------
Typing in the txt_ServiceZip field a "4" the sSQL variable has a value of ZipCode LIKE '4%'
The dataset.select actually returns a row array with a length of zero meaning no rows returned.
I know running the actual query with that WHERE parameter it returns 4600+ rows.
Am I missing something? Are we not allowed to use LIKE in the select statement?
Many thanks in advance!
Angela
I have a dataset that has a table in it called zipcodes. Declared it this way...
' Create a new DataTable and set a DataColumn object as the primary key.
dsInfoServices.Tables.Add("ZipCode")
Dim keys(1) As DataColumn
Dim myColumn As DataColumn
' Create column 1 and add it to the array.
myColumn = New DataColumn
myColumn.DataType = System.Type.GetType("System.String")
myColumn.ColumnName = "ZipCode"
dsInfoServices.Tables("ZipCode").Columns.Add(myColumn)
' Add the column to the array.
keys(0) = myColumn
' Set the PrimaryKeys property to the array.
dsInfoServices.Tables("ZipCode").PrimaryKey = keys
sqlCmdServices.CommandText = "spGetZipCodes"
sqlAdapterServices.Fill(dsInfoServices, "ZipCodes")
Then I am trying to autofill a text field once they change it so I do the following:
Private Sub txt_ServiceZip_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_ServiceZip.TextChanged
Dim sSQL As String
sSQL = "Zipcode Like '" & Me.txt_ServiceZip.Text & "%'"
Dim rows() As DataRow = dsInfoServices.Tables("ZipCode").Select(sSQL)
If (Not rows.Length > 0) Then
Dim iLength As Integer
iLength = Len(Me.txt_ServiceZip.Text)
Me.cmb_ServiceState.SelectedValue = rows(0).Item("StateID")
sqlCmdServices.CommandText = "spGetCities '" & Me.txt_ServiceZip.Text & "'"
sqlAdapterServices.Fill(dsInfoServices, "Cities")
Me.txt_ServiceZip.Text = rows(0).Item("ZipCode")
Me.txt_ServiceZip.SelectionStart = iLength
Me.txt_ServiceZip.SelectionLength = Len(rows(0).Item("ZipCode"))
End If
End Sub
----------------------------
Typing in the txt_ServiceZip field a "4" the sSQL variable has a value of ZipCode LIKE '4%'
The dataset.select actually returns a row array with a length of zero meaning no rows returned.
I know running the actual query with that WHERE parameter it returns 4600+ rows.
Am I missing something? Are we not allowed to use LIKE in the select statement?
Many thanks in advance!
Angela