Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataSet query

Status
Not open for further replies.

LovinIt

Programmer
Dec 20, 2004
17
US
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
 
To any who took the time... I really appreciate it...

Sometimes you have to release a bug and ask for help and then the Error hits you immediately..Which is what happened

My select statement the table I was referencing was invalid. I was accessing "zipcode" which doesn't exist and it should have been "zipcodes" with an s. As soon as I fixed this it worked...

Many thanks anyway!

Angela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top