
StringBuilder sb=null;
sb=new StringBuilders;
sb.Append("Insert into dummy(name,amount) values");
foreach(Control ctl in this.FlowLayoutPanel1.Controls)
{
if( ctls.Name.Contains("tb") && ctl is TextBox)
{
sb.Append(ctl.Text);
}
}
foreach(Control bbl in this.FlowLayoutPanel1.Controls)
{
if (bbl.Name.Contians("bb") && bb is TextBoxe)
{
sb.Append(bbl.Text);
}
}
SqlCommand cmd=new SqlCommand(sb.ToString(),con);
cmd.CommandType=CommandType.Text;
cmd.ExecuteNoneQuery();


It could be something like this:
StringBuilder sb = new StringBuilder();
sb.Append("Insert into dummy(name,amount) values ('");
foreach(Control ctl in this.FlowLayoutPanel1.Controls)
{
if( ctls.Name.Contains("tb") && ctl is TextBox)
{
sb.Append(ctl.Text + "',");
}
}
foreach(Control bbl in this.FlowLayoutPanel1.Controls)
{
if (bbl.Name.Contians("bb") && bb is TextBoxe)
{
sb.Append(bbl.Text + ")");
}
}
// to verify the constructed command
MessageBox.Show(sb.ToString());
SqlCommand cmd=new SqlCommand(sb.ToString(),con);
cmd.CommandType=CommandType.Text;
cmd.ExecuteNoneQuery();
This is the syntax for the SQL INSERT statement:
<pre>INSERT INTO <table_name> [(<column list>)] VALUES (<values list>)</pre>
So, your INSERT string should look like this:
<pre>Insert into dummy(name,amount) values (“something”,some_value)</pre>
but it seems that you are constructing it like this:
<pre>insert into dummy(name,amount) values something some_value</pre>
To debug it, I would display the contents of the command text before running it.


thx sir, but the problem is how to rectify it in above foreach loop as the value arise from runtime controls please help me.
and once again thx for feedback
Btw, using dynamically created SQL commands could allow SQL injection attacks. You might want to investigate about parameterized commands.
thx sir for ur feedback I have develop the same in perameterized way. i don’t know how to accept ur answer please tell me to how to accept ur answer for give to credit.