Reputation: 13
Im getting the following error:
"A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Incorrect syntax near ')'. If there is a handler for this exception, the program may be safely continued."
Is this syntax? i really cant figure this out, can anyone tell what i am doing wrong?
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("A Atualizar dados...");
bool check = true;
do
{
string connectionString = @"Data Source=.\wintouch;Initial Catalog=bbl;User ID=sa;Password=Pa$$w0rd";
string queryString = string.Empty;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
queryString = "UPDATE wgcdoccab SET merc1 = merc1/2 WHERE numdoc = (SELECT MAX(numdoc) FROM WGCDOCCAB WHERE serie ='1' and tipodoc ='FSS' and contribuinte ='999999990' and datadoc = CONVERT(varchar(10),(dateadd(dd, -1, getdate())), 120))";
SqlCommand command = new SqlCommand(queryString, connection);
command.ExecuteNonQuery();
connection.Close();
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
queryString = "SELECT max(numdoc) FROM wgcdoccab WHERE serie ='1' and tipodoc ='FSS' and contribuinte ='999999990' and datadoc = CONVERT(varchar(10),(dateadd(dd, -1, getdate())), 120))";
using (SqlCommand command = new SqlCommand(queryString, connection))
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
check = true;
}
else
{
check = false;
MessageBox.Show("Dados atualizados com sucesso");
}
command.Connection.Close();
}
}
}
while (check);
Upvotes: 0
Views: 339
Reputation: 4163
Check your SQL Statements. This line has too many parentheses:
queryString = "SELECT max(numdoc) FROM wgcdoccab WHERE serie ='1' and tipodoc ='FSS' and contribuinte ='999999990' and datadoc = CONVERT(varchar(10),(dateadd(dd, -1, getdate())), 120))";
Upvotes: 1