Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, im using SQL server management for my database and Visual studio 2010,i need help in filtering data. i want to filter row and put it in a textbox and filter another row in another text box vb.
ex.
ID--------- Date -------- msg_num ------------ Message <<<column name="">10001 -- 01/01/2012 ------ msg1 ------------- Blah! Blah!
10002 -- 01/01/2012 ------ msg2 ------------- Please Help!
10003 -- 01/01/2012 ------ msg3 ------------- happy happy
10004 -- 01/01/2012 ------ msg4 ------------- i don't know
10005 -- 01/01/2012 ------ msg3 ------------- xxxxxxxxx
10006 -- 01/02/2012 ------ msg1 ------------- dasdasdad
10007 -- 01/02/2012 ------ msg2 ------------- qqqqqqqqqqq
10008 -- 01/02/2012 ------ msg3 ------------- eeeeeeeeeeeeeeeeee
10009 -- 01/02/2012 ------ msg4 ------------- yyyyyyyyyyyyyyyyyy
10010 -- 01/02/2012 ------ msg3 ------------- zzzzzzzzzzzzzzzzzz

first i want to filter the date 01/01/2012
then filter 10004 and put it in Textbox1,
filter 10002 put it in Textbox2,
and filter 10005 to Textbox3

output:
Textbox1.text = "i don't know"
Textbox2.text = "Please Help!"
Textbox3.text = xxxxxxxxxxxxxxx

*Message its not fix its changable...
Posted
Updated 16-Mar-12 7:16am
v3

1 solution

Where the data is stored, is not given in the question
If the data is in a DataTable and the format of ID, Date, msg etc. is string then the following code can be used to do the task mentioned in the question
VB
'Dim MessageTable as DataTable
'Data is filled in the DataTable elsewhere in the program

Public Function GetMessage(ByVal FilterDate as String, ByVal FilterID as String) as String
    Dim FilteredRows as DataRow()
    FilteredRows = MessageTable.Select("Date='" & FilterDate & "' and ID='" & FilterID & "'")
    If FilteredRows.Length > 0 then
        Return FilteredRows(0).Item("Message")
    Else
        Return ""
    End if
End Function
'Then to assign the text to TextBox

TextBox1.Text = GetMessage("01/01/2012","10004")
TextBox2.Text = GetMessage("01/01/2012","10002")
TextBox3.Text = GetMessage("01/01/2012","10005")
 
Share this answer
 
v2
Comments
rayskull04 16-Mar-12 12:57pm    
im using SQL sever management studio for my database...
i tried to run the program and recieved an error of "OBJECT \REFERENCE NOT SET TO AN INSTANT OF AN OBJECT"
ProEnggSoft 16-Mar-12 13:52pm    
Please see this article
http://www.codeproject.com/Articles/341274/General-purpose-class-to-fill-DataTable-s-from-Dat
to fill the DataTables, then you can use the above function to filter the data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900