I am using C#, VS 2005 and SQL 2000
My code is:
StringBuilder sb = new StringBuilder();
sb.Append("insert into dummy(name,amount)values");
foreach (Control ctl in this.flowLayoutPanel1.Controls)
{
if (ctl.Name.Contains("tb") && ctl is TextBox)
{
sb.Append(ctl.Text);
}
}
foreach(Control bbl in this.flowLayoutPanel1.Controls)
{
if(bbl.Name.Contains("bb") && bbl is TextBox)
{
sb.Append(bbl.Text);
}
}
SqlCommand cmd = new SqlCommand(sb.ToString(), con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
It throws an error like this:
Incorrect syntax near values
Please help me.
The values themselves need to be in brackets and separated by commas as well.
I think your code produces this:
But you need to change it to produce this:
some example code that will do this is:
This code is far from ideal, but it should fix your SQL syntax error. Some other enhancements you should think about are:
However, a MUCH better way would be to do this (EDITED to help mahesh with his coding, now includes multiple inserts):