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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing string from a query into an Array?

Status
Not open for further replies.

JaneB19

Technical User
Jun 27, 2002
110
GB
Hi,
I'm hoping that somebody can help me out with my little problem, and that I'm just being really daft!

Ok, an explaination of what I am attempting to do:

I've got 4 SQL commands which execute depending on a radio button selection. Which command is executed shouldn't matter for the next bit. I want to pass the results of the commands into an Array, this is so that I can do a comparison with the ArrayItems to a pattern. I'm having problems with that too, as ASP.net doesn't support the LIKE statement supposedly!? I've tried doing the following for passing the SQL result to the ArrayList:


Do While counter < No_Letters.SelectedValue
If (txtLtFnd.Text = "") Then
Exit Do
Else
txtLtFnd.Text.CompareTo(ojbCommand.ExecuteReader())
Dim results As ArrayList
If txtLtFnd.Equals(comparison) Then
results.Add(comparison)
Else
Exit Do
End If
End If
Loop


But this won't let the page to be displayed once the Submit button has been clicked!

Can anybody help me with any of this?

Thanks in advance for any pointers or help that you can give me.

Jane
 
I am not sure I understand what you are trying to do.

What I think you are trying to do is execute a SQL statement, and step through the result set looking at each value to see if it matches a text pattern?

In this case, the normal way to do this would be to use a data reader object to read the data, retrieving the column of interest into a string.

For the comparison with the pattern, there are two ways.

The Like comparator is supported by vb.net.

OR

Use regular expressions. They are much more powerful and flexible.

So for example (though I'm just typing this straight in, so it might be wrong

Code:
'imports System.Text.RegularExpressions and System.Data.OracleClient - the method is the same for any .net data provider

'open connection
cn.open
'set SQL
cmd.CommandText = "Select Column from Table where OtherColum in (1,2,3,4)"
'execute reader based on command
dim dr as OracleDataReader = cmd.executeQuery()
'set up regex
dim re as new Regex("MyPattern")
'loop thru result set
while dr.read
'compare column to pattern
if re.IsMatch(dr("Column").toString)) then
'do something
end if
end while

Hope this helps

Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top