Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Select query within a datatable in vb.net

Posted on 2008-11-18
14
Medium Priority
?
5,479 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:ASINGH1974
  • 6
  • 5
12 Comments
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22983948
Something like this?

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

Wayne
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22983951
1. Did you try:
tmpviewStrSearchText = "(myField like '%hello%' or myField2 like '%hi%') and myField3 not like '%what%'

2. What exactly do you mean ?
0
 

Author Comment

by:ASINGH1974
ID: 23002773
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Dhaest
ID: 23002959
>> tmpviewStrSearchText=%h_

You need to include the field

tmpviewStrSearchText= " myField like '%h_'"
0
 

Author Comment

by:ASINGH1974
ID: 23011534
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 23011613
Can you post the name of your field !


Wildcard characters
http://www.devasp.net/net/articles/display/702.html
0
 

Author Comment

by:ASINGH1974
ID: 23011651
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 23011743
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
 

Author Comment

by:ASINGH1974
ID: 23011808
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 23011823
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
 

Author Comment

by:ASINGH1974
ID: 23011872
there is no row comes after filtering
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 23011891
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question