Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I can write any query from a text box for eg..
 
Select * from table
 
select product from food
 
Delete * from good
 
select product,quantity,id from food
 
How can i get the food or the word just after the word FROM
 
i need to extact just table name
 
please help anyone
Posted 8-Mar-14 9:14am
mrukr453
Edited 8-Mar-14 9:20am
Maciej Los158.8K
v2
Comments
Maciej Los at 8-Mar-14 14:21pm
   
What have you tried? Where are you stuck?
mrukr at 8-Mar-14 14:28pm
   
Dim str As String = textbox1.text
If str.Contains("FROM"C) Then
Dim index As Integer = str.IndexOf("FROM"C)
Dim result As String = str.Substring(0, index)
Console.WriteLine("result: " & result)
End If
 
im not sure if this is not working for the result

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please, read my comment to the question.
 
All you need to do is to find FROM word than to extract table name.
How to: Search Strings Using String Methods (C# Programming Guide)[^]
How to: Search Within a String (Visual Basic)[^]
How to: Search Strings Using Regular Expressions (C# Programming Guide)[^] - true, it's c#, but you can convert it via for example developerfusion online converter[^]
 
But i need to warn you. In some cases, sql query could looks like:
SELECT <field list>
FROM (
    SELECT <field list>
    FROM TableName
    WHERE <condition>
) AS T
WHERE <condition>
What do you expect to find?
 
Please, read these articles:
SQL Parser[^]
Microsoft.SqlServer.Management.SqlParser.Parser Namespace[^]
There you'll find many usefull information.
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 8 Mar 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100