vb.net database query [generation of SQL Strings]

Source: Internet
Author: User
Tags sql server query query
Data | database | String---------SQL generation----------
A task is a multiple-condition query that uses in (X,y) when a user separates a query by commas, but an error occurs when the field corresponding to the database (ACCESS) is a character type, of course! If it is in (' X ', ' y ') there is no problem!
The following code is the operation of the string, which returns ' X ', ' Y '.

'-----Accept the string to be processed-------
Function tool_distest (ByVal textbefore as String)
Dim Textafter () as String
Dim Intnum, Inttextlen, K, I as Integer
Intnum = 1
Inttextlen = Len (Textbefore)
'--------How many query conditions are calculated--------
For i = 1 to Inttextlen
If Mid (Textbefore, I, 1) = "," Then
Intnum = intnum + 1
End If
Next
'-----------------------------------
ReDim Textafter (Intnum)
K = 1
'--------put each condition in the array---------
For i = 1 to Inttextlen
If Mid (Textbefore, I, 1) = "," Then
K + 1
Else
Textafter (k) = Textafter (k) & Mid (Textbefore, I, 1)
End If
Next
'----------------------
Dim strtemp as String
'--------add '----------for each condition
For i = 1 to Intnum
strtemp = Textafter (i)
Textafter (i) = "'" & strtemp & "'"
Next
'----------------------
strtemp = ""
'------Add a separator condition, '------
For i = 1 to Intnum
strtemp = strtemp & Textafter (i) & ","
Next
'------------------
'------Remove the last,------
strtemp = Mid (strtemp, 1, Len (strtemp)-1)
'-------------------
Return strtemp
End Function

Finally in SQL Server to try again, found that SQL Server query in (x,y) to query the character type is OK, (SQL Server is more than access strengths, hehe)
---------End-------


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.