I need some advice here. I am making an application to get a particular SQL statement within a VB Form but do not know which would be the best option to do so.
For example i have this sentence on to explain:
FROM sys.master_files WITH (NOLOCK)
But what i need is
FROM sys.master_files
I need to get the FROM
and the next thing like sys.master_files
The first moment this is just what I need, it is a basic application, only to catch the FROM and the next thing that comes.
Now I've been researching and looking at some questions that had already been made in StackOverFlow and I was wondering if the Regex.Match
is a faster way to do this check or if I could use the IndexOf
but the I did not understand very well how it works.
This is what i made so far on the Code.
private void btnSearch_Click(object sender, EventArgs e)
{
string value = cboParam.Text;
string[] reservedWords = { "FROM", "SELECT", "JOIN", "UPDATE", "DROP", "ALTER", "CREATE" };
if (cboParam.Text == "")
{
MessageBox.Show("Wrong try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
List<string> listParam = new List<string>();
listParam.Add(value);
if (selectedPath == null && openFileDialog.FileNames == null)
{
MessageBox.Show("Choose a directory please.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (selectedPath != null)
{
foreach (string str in selectedPath)
{
string split = " ";
string readText = File.ReadAllText(str)
.Replace("\n", split)
.Replace("\r", split)
.Replace("_", split)
.Replace("-", split)
.Replace("SQL", split)
.Replace("sql", split)
.Replace("FROM", split)
.Replace("from", split)
.Replace("JOIN", split)
.Replace("join", split)
.Replace("UPDATE", split)
.Replace("update", split)
.Replace("DELETE", split)
.Replace("delete", split);
readText.IndexOf(value);
}
}
else if (openFileDialog.FileNames != null)
{
foreach (string str in openFileDialog.FileNames)
{
string split = "\nGO";
string readText = File.ReadAllText(str)
.Replace("\n", split)
.Replace("\r", split)
.Replace("_", split)
.Replace("-", split)
.Replace("SQL", split)
.Replace("sql", split)
.Replace("FROM", split)
.Replace("from", split)
.Replace("JOIN", split)
.Replace("join", split)
.Replace("UPDATE", split)
.Replace("update", split)
.Replace("DELETE", split)
.Replace("delete", split);
readText.IndexOf(value);
}
}
}
}
That's what I had, I was trying to use the IndexOf but can not give a continuity because I did not understand the operation of it.
For a better understanding I'm from Brazil so I changed a bit the pair variables of code into English to become "easy" to understand the code.