M
MyCatAlex
Guest
I have this code. It is similar to many other procedures to access my SQL Server I have written before. Now it gives me a strange message and I don't understand what it is.
private void combo_SQLCodePackages_PG1_SelectedIndexChanged(object sender, EventArgs e)
{
string tableName = (string)this.combo_SQLCodePackages_PG1.Text;
Service service = new Service();
Server srv = service.GetServer("SqlCodeSamples");
using (SqlConnection conn = new SqlConnection
(srv.ConnectionContext.ConnectionString))
{
conn.Open();
SqlCommand cmdm = new SqlCommand();
cmdm.Connection = conn;
cmdm.CommandType = CommandType.Text;
cmdm.CommandText = "SELECT * FROM [dbo].[" + tableName +
"] WHERE 'RECORD_ID' = '" + numericUpDown_PG1.Value +"' )";
try
{
using (SqlDataReader rdr = cmdm.ExecuteReader(CommandBehavior.SequentialAccess)) <== ERROR Incorrect syntax near ')'
{
if (rdr.HasRows == true)
{
foreach (System.Data.Common.DbDataRecord row in rdr)
{
numericUpDown_PG1.Value = (int)row["RECORD_ID"];
tBoxRecords_PG1.Text = (string)row["SQL_TITLE"];
richTextBox1_PG1.Text = (string)row["SQL_CODE"];
}
}
if (rdr.IsClosed == false)
{
rdr.Close();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + " " + ex.InnerException);
TSP.textToSpeech2("Operation failed");
}
}
} // combo_SQLCodePackages_PG1_SelectedIndexChanged
The message is marked at the code line. It is "Incorrect syntax near ')' I get it at runtime, the code compiles well. There is a similar routine in the same application. That one also compiles and causes no runtime problems.
What is it?
Thanks, - MyCatAlex
Continue reading...
private void combo_SQLCodePackages_PG1_SelectedIndexChanged(object sender, EventArgs e)
{
string tableName = (string)this.combo_SQLCodePackages_PG1.Text;
Service service = new Service();
Server srv = service.GetServer("SqlCodeSamples");
using (SqlConnection conn = new SqlConnection
(srv.ConnectionContext.ConnectionString))
{
conn.Open();
SqlCommand cmdm = new SqlCommand();
cmdm.Connection = conn;
cmdm.CommandType = CommandType.Text;
cmdm.CommandText = "SELECT * FROM [dbo].[" + tableName +
"] WHERE 'RECORD_ID' = '" + numericUpDown_PG1.Value +"' )";
try
{
using (SqlDataReader rdr = cmdm.ExecuteReader(CommandBehavior.SequentialAccess)) <== ERROR Incorrect syntax near ')'
{
if (rdr.HasRows == true)
{
foreach (System.Data.Common.DbDataRecord row in rdr)
{
numericUpDown_PG1.Value = (int)row["RECORD_ID"];
tBoxRecords_PG1.Text = (string)row["SQL_TITLE"];
richTextBox1_PG1.Text = (string)row["SQL_CODE"];
}
}
if (rdr.IsClosed == false)
{
rdr.Close();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + " " + ex.InnerException);
TSP.textToSpeech2("Operation failed");
}
}
} // combo_SQLCodePackages_PG1_SelectedIndexChanged
The message is marked at the code line. It is "Incorrect syntax near ')' I get it at runtime, the code compiles well. There is a similar routine in the same application. That one also compiles and causes no runtime problems.
What is it?
Thanks, - MyCatAlex
Continue reading...