Reputation: 23
HI everyone i hope someone can help me out i am learning c# so far i have written a couple of useful programs, but now i a stumped from a particular problem i have googled the query i thought i would need. this is my code
try
{
con.Open();
cmd = new SqlCommand("SELECT * from LMNormal", con);
cmd.CommandText = ("INSERT INTO LMNormal (upc,cert_code,description,cost,normal_price,pricemethod,groupprice,quantity,special_price,specialcost,specialpricemethod,specialgroupprice,specialquantity,start_date,end_date,pack,size,unitofmeasure) SELECT (upc,cert_code,description,cost,normal_price,pricemethod,groupprice,quantity,special_price,specialcost,specialpricemethod,specialgroupprice,specialquantity,start_date,end_date,pack,size,unitofmeasure) from products where (modified >= @now) and (advertised=@false)");
cmd.Parameters.AddWithValue("@now", now);
cmd.Parameters.AddWithValue("@false", selected);
cmd.Connection = con;
cmd.ExecuteNonQuery();
timer1.Start();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
When the program executes it catch my error and says incorrect syn tact near ',' i am having a hard time trying to figure out where this comma is.
Thanks for any input
Upvotes: 2
Views: 9753
Reputation: 2604
Remove '(' and ')' from your select query
cmd.CommandText = ("INSERT INTO LMNormal (upc,cert_code,description,cost,normal_price,pricemethod,groupprice,quantity,special_price,specialcost,specialpricemethod,specialgroupprice,specialquantity,start_date,end_date,pack,size,unitofmeasure)
SELECT upc,cert_code,description,cost,normal_price,pricemethod,groupprice,quantity,special_price,specialcost,specialpricemethod,specialgroupprice,specialquantity,start_date,end_date,pack,size,unitofmeasure from products where modified >= @now and advertised=@false");
Upvotes: 1
Reputation: 263933
the only thing you need to do is to remove the parenthesis that wraps the columns in your select statement, eg
INSERT INTO LMNormal (upc, cert_code, description, ..., unitofmeasure)
SELECT upc, cert_code, description, ..., unitofmeasure
FROM products
WHERE (modified >= @now) and (advertised = @false)
Upvotes: 9