Select query within a datatable in vb.net

Hi all experts,

my first question is
1)
I have a datatable dtChattable.
and my search text is %hello% or %hi% not %what%
in which i want to apply a select query like

  Dim dataRows() As DataRow = dtChattable.Select(tmpviewStrSearchText)

2)
if my search text is %h_
then it is not searching at fron end.How could i do It.

Please suggest me regarding it.
ASINGH1974Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Something like this?

    Dim dataRows() As DataRow = dtChattable.Select("[FieldName] LIKE '" & tmpviewStrSearchText & "'")

Wayne
0
DhaestCommented:
1. Did you try:
tmpviewStrSearchText = "(myField like '%hello%' or myField2 like '%hi%') and myField3 not like '%what%'

2. What exactly do you mean ?
0
ASINGH1974Author Commented:
my first question is
1)
I have a datatable dtChattable.
if my search text is
tmpviewStrSearchText=%h_
in which i want to apply a select query like

  Dim dataRows() As DataRow = dtChattable.Select(tmpviewStrSearchText)

then it is not searching at datatable .How could i do It.

Please let me know about it.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

DhaestCommented:
>> tmpviewStrSearchText=%h_

You need to include the field

tmpviewStrSearchText= " myField like '%h_'"
0
ASINGH1974Author Commented:
Hi experts,

suppose i have a dataset in which first column consists text hi
second hi how r u.

tmpviewStrSearchText= " myField like '%h_'"

now i want use
datarow[] dr=dataset.table[0].select(tmpviewStrSearchText)
but it is not filtering there is no result is coming it is not select the row which consists first character h and second may be anyone.

please let me know.

0
DhaestCommented:
Can you post the name of your field !


Wildcard characters
http://www.devasp.net/net/articles/display/702.html
0
ASINGH1974Author Commented:
my table structure is

id          text
1           hi
2           how r u
3           ok close it now.

now i want to

tmpviewStrSearchText= " text like '%h_'"
datarow[] dr=dataset.table[0].select(tmpviewStrSearchText)

but it is not filtering there is no result is coming it is not select the row which consists first character h and second may be anyone.
0
DhaestCommented:
Probably because text is a reserved word.
Can you try to alter your table where text will be text2

id          text2
1           hi
2           how r u
3           ok close it now.

now i want to

tmpviewStrSearchText= " text2 like 'h_'"
datarow[] dr=dataset.table[0].select(tmpviewStrSearchText)
0
ASINGH1974Author Commented:
just for example i keep the name of columns text it is not text name in real it is chattext

i have tried this underscore sign is not gie any result in select method of datatable
0
DhaestCommented:
How did you test to see if you had records


    ' Use the Select method to find all rows matching the filter.
    foundRows = table.Select("chattext like 'h_'")

    Dim i As Integer
    ' Print column 0 of each returned row.
    For i = 0 to foundRows.GetUpperBound(0)
       Console.WriteLine(foundRows(i)(0))
    Next i
0
ASINGH1974Author Commented:
there is no row comes after filtering
0
DhaestCommented:
There are 2 possible solutions for selecting the data:
1) foundRows = Dataset.tables[0].Select("chattext like 'h_'")
2) Dim view as DataView = new DataView(ds.Tables[0]);
    view.RowFilter = "chattext like 'h_'"
For Each drv As DataRowView In view
    Console.WriteLine(drv("Name").ToString())
Next



Filtering and Sorting Directly in Data Tables
http://msdn.microsoft.com/en-us/library/zk13kdh0(VS.71).aspx

Filtering and Sorting Data Using Data Views
http://msdn.microsoft.com/en-us/library/69c06922(VS.71).aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.