Start Free Trial
Come for the solution, stay for everything else.
Start Free Trial
Recognize SQL Queries from TextBox and Execute Separately
I am doing a project where user enters SQL Queries like in SQL Management Editor . Many Individual queries ..
Here even i am doing the same . If user writes 2 or more queries in a text box they all needs to be recognized separately Like individual queries and needs be executed separately.
Microsoft SQL Server
8/22/2022 - Mon
HI, try this on the button event:
Dim conn As SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Dim i, j As Integer
Dim qry(10) As String ' Say max 10 queries
Dim str1 As String
str1 = Me.TextBox3.Text
While Len(str1) > 5
qry(i) = Mid$(UCase(str1), 1, InStr(str1, Chr(13)))
str1 = Mid$(str1, InStr(str1, Chr(13)) + 1, Len(str1))
i = i + 1
conn = New SqlConnection(Configuratio
For j = 0 To 9
cmd.CommandText = qry(j)
dr = cmd.ExecuteReader
Havent tested it, but guess it should work properly.
See the text box might contain 1st query which might have length of 15 lines and 2nd with 2 lines and 3rd with 1 line .
But while executing currently i am using directly textbox, that is wrong . I want to know how can i detect 3 queries written and differentiate them . Executing part already i have done with that.
Now only i need to find how many individual queries are there for which the output needs to be shown separately .
The solution which I have posted works if Enter is pressed after each query and doesnt matter if its single line or 15 lines.
Else you may ask the users to seperate the queries by semicolon and modify the above code accordingly.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
Sorry Have Checked the code . It wont return any query in the array, Just it will be filled with space for every index and Even throws Array out of index exception after completing 9th while condition .
ASKER CERTIFIED SOLUTION
Log in or sign up to see answer
Become an EE member today
7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Plans and Pricing
Certified Expert Program
© 1996-2022 Experts Exchange, LLC. All rights reserved. Covered by US Patent