hi developers ,
in my project am createddynamic textboxes with jquery.
i want to insert all the dynamic textbox values into the database.
value was inserting if am create only one textbox value.
if am create more than one dynamic textbox values na it will inserted So many times more.
for example if i am created 2dynamic textboxes na actually 2 should be inserted times only but in my code the values are inserted 4 times.
for example if i am created 3 dynamic textboxes na actually 3 should be inserted times only but in my code the values are inserted 6 times.
also the problem is am not comfortable with foreach loop.
My using code is below:
protected void btnsave_Click(object sender, EventArgs e)
{
string[] textboxValues1 = Request.Form.GetValues("DynamicTextBox1");
string[] textboxValues2 = Request.Form.GetValues("DynamicTextBox2");
JavaScriptSerializer serializer = new JavaScriptSerializer();
this.Values1 = serializer.Serialize(textboxValues1);
this.Values2 = serializer.Serialize(textboxValues2);
string message1 = "";
string message2 = "";
string message3 = "";
if (textboxValues1 != null && textboxValues2 != null)
{
foreach (string textboxValue1 in textboxValues1)
{
message1 = textboxValue1 + " ";
foreach (string textboxValue2 in textboxValues2)
{
message2 = textboxValue2 + " ";
foreach (string textboxValue3 in textboxValues3)
{
message3 = textboxValue3 + " ";
SqlCommand cmd = new SqlCommand("INSERT INTO dynamictext(val1,val2,val3) VALUES(@val1, @val2,@val3)", con);
cmd.Parameters.AddWithValue("@val1", message1.ToString());
cmd.Parameters.AddWithValue("@val2", message2.ToString());
cmd.Parameters.AddWithValue("@val3", message3.ToString());
cmd.ExecuteNonQuery();
Response.Write("Inserted");
}
}
}
}
}
if am make any mistakes in my code please suggest me to how i am get exact output.
thanks with
Paul.S