c# - Error on the query string SQL -
im getting following error:
"a first chance exception of type 'system.data.sqlclient.sqlexception' occurred in system.data.dll additional information: incorrect syntax near ')'. if there handler exception, program may safely continued."
is syntax? cant figure out, can tell doing wrong?
private void button2_click(object sender, eventargs e) { messagebox.show("a atualizar dados..."); bool check = true; { 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 numdoc = (select max(numdoc) wgcdoccab serie ='1' , tipodoc ='fss' , contribuinte ='999999990' , 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) wgcdoccab serie ='1' , tipodoc ='fss' , contribuinte ='999999990' , 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);
check sql statements. line has many parentheses:
querystring = "select max(numdoc) wgcdoccab serie ='1' , tipodoc ='fss' , contribuinte ='999999990' , datadoc = convert(varchar(10),(dateadd(dd, -1, getdate())), 120))";
Comments
Post a Comment