Vb.net如何在“”之间得到一个Dim语句?

时间:2014-03-30 19:44:26

标签: mysql vb.net

我想在“”之间得到一个Dim声明。

Dim TEST As String =“1”& “2”& “3”

SQL =“SELECT * from MYDATABASE where ”这是我想要的暗淡语句“喜欢'%'& search.Text& “%'”

我想把它里面的多个桌子放进去。 这将如何运作?

1 个答案:

答案 0 :(得分:0)

我意识到你已经说过上面的表了,但是,我怀疑你的意见是指你的意思是Columns not Tables,你在谈论查询姓氏和名字?

Dim Columns As New List(Of String)

'Add as many columns as you like here...
Columns.Add("FirstName")
Columns.Add("LastName")
Columns.Add("Address")

'Initialise you Query String...
Dim SQL As String = "SELECT * FROM MyDatabase.MyTable WHERE "

'Loop through all the columns you want to search...
For Each Column As String In Columns

    'Check if this is the last item... If so, we don't need the trailing OR!
    If ReferenceEquals(Columns.Item(Columns.Count - 1), Column) Then

        SQL &= Column & " LIKE '%" & search.Text & "%'"

    Else

        SQL &= Column & " LIKE '%" & search.Text & "%' OR "

    End If

Next

'
'Go on and perform your query...
'

但是,如果你真的指的是不同的表格,那么你也必须加入一些表格。

另外,正如评论中所提到的,这是不安全的,并且容易受到SQL注入......但如果您处于高信任环境中,它将会起作用...