Visual Basic Development Bookmark and Share   
 Home > Visual Basic General > Sql query to array
 

Sql query to array

Good day!

I have here a sample strings,fromRichTextBox

Select * from TestTable01

Update TestTable02 set Col01 = 'Column01' where Col01 = 'Col1'

Select * from TestTable02

I want extract each of this query and place it to a array.

k3nTm  Monday, January 26, 2009 5:59 AM
Ok its simple

Dim myarray As String() = RichTextBox1.Lines

If you want value then simply use myarray(0), you can iterate this way

for each str as string in myarray

messagebox.show(str)

next

Now if you want to remove empty lines from an array you could iterate the above way and check for empty lines or use this Linq method

Dim list1 As List(Of String) = RichTextBox1.Lines.ToList
Dim matchset As IEnumerable(Of String) = From match In list1 _
Where match.Trim <> "" Select match
Dim MyarraywithoutBlank As String() = matchset.ToArray

Make sure you have .net 3.5 enabled project for linq methods.


Arjun Paudel
Arjun Paudel  Monday, January 26, 2009 8:20 AM
Ok its simple

Dim myarray As String() = RichTextBox1.Lines

If you want value then simply use myarray(0), you can iterate this way

for each str as string in myarray

messagebox.show(str)

next

Now if you want to remove empty lines from an array you could iterate the above way and check for empty lines or use this Linq method

Dim list1 As List(Of String) = RichTextBox1.Lines.ToList
Dim matchset As IEnumerable(Of String) = From match In list1 _
Where match.Trim <> "" Select match
Dim MyarraywithoutBlank As String() = matchset.ToArray

Make sure you have .net 3.5 enabled project for linq methods.


Arjun Paudel
Arjun Paudel  Monday, January 26, 2009 8:20 AM

thank you!

what if I have this strings?

Update TestTable02

set Col01 = 'Column01'

where Col01 = 'Col1'

how can I make it into on statement?

k3nTm  Tuesday, January 27, 2009 3:10 AM
You need to learn the Regular Expression to implement your requirement. Take a look at this article about regular expression.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Riquel_Dong  Thursday, January 29, 2009 6:36 AM

You can use google to search for other answers

Custom Search

More Threads

• Find cursor's x,y coordinates in a richtextbox
• How to make comments appear in sub or function
• Exporting Datagridview
• Displaying numbers in scientific notation?
• Greek Characters in EXCEL Basic Script
• how to save the DLL of differnt project in the same diectory
• DataTable.Select Sorting Problem
• How to disable a computer by using ADSI?
• LINQ Query with Sum and Group By is adding Decimal Precision
• in vb.net i need to parse a document file and display email,name