VB.net过滤数据库中的数据 [英] VB.net filtering a data from database
问题描述
您好,即时通讯将SQL Server管理用于我的数据库和Visual Studio 2010,我需要过滤数据方面的帮助.我想过滤行并将其放在文本框中,并过滤另一行在另一个文本框中vb.
例如
ID ---------日期-------- msg_num ------------消息<<<列名="> 10001-2012年1月1日------ msg1 ------------- ah!布拉!
10002-01/01/2012 ------ msg2 -------------请帮助!
10003-01/01/2012 ------ msg3 ------------- happy happy
10004-01/01/2012 ------ msg4 -------------我不知道
10005-01/01/2012 ------ msg3 ------------- xxxxxxxxx
10006-2012年1月2日------ msg1 ------------- dasdasdad
10007-2012年1月2日------ msg2 ------------- qqqqqqqqqqq
10008-01/02/2012 ------ msg3 ------------- eeeeeeeeeeeeeeeeeeee
10009-2012年1月2日------ msg4 ------------- yyyyyyyyyyyyyyyy
10010-01/02/2012 ------ msg3 ------------- zzzzzzzzzzzzzzzzzzzz
首先,我想过滤日期01/01/2012
然后过滤10004并将其放在Textbox1中,
过滤器10002将其放入Textbox2中,
并将10005过滤到Textbox3
输出:
Textbox1.text =我不知道"
Textbox2.text =请帮助!"
Textbox3.text = xxxxxxxxxxxxxxx
* 消息无法解决其可更改的问题...
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...
推荐答案
问题中未给出存储数据的位置
如果数据位于DataTable
中,并且ID, Date, msg
等格式为字符串,则可以使用以下代码完成问题中提到的任务
Where the data is stored, is not given in the question
If the data is in aDataTable
and the format ofID, Date, msg
etc. is string then the following code can be used to do the task mentioned in the question
'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")
这篇关于VB.net过滤数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!