I need to add a same data multiple times to the database.Its working in sql, but when I apply the querry in asp.net its not working. It shows error near to 'go'. Here is my code.
protected void Button26_Click(object sender, EventArgs e)
{
Control control = null;
if (GridView1.FooterRow != null)
{
control = GridView1.FooterRow;
}
else
{
control = GridView1.Controls[0].Controls[0];
}
string SlNo = (control.FindControl("txtSlNo") as TextBox).Text;
string Code = (control.FindControl("txtcode") as TextBox).Text;
string Qty = (control.FindControl("txtqty") as TextBox).Text;
using (SqlConnection con = new SqlConnection("Data Source=xxxxx;Initial Catalog=xxxxx;User ID=xx;Password=xxxxx"))
{
using (SqlCommand cmd = new SqlCommand())
{
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO [Itable1](Num,Code,Qty) VALUES(@Num,@Code,@Qty) go 4 ";
cmd.Parameters.AddWithValue("@CODE", Code);
cmd.Parameters.AddWithValue("@Num", SlNo);
cmd.Parameters.AddWithValue("@Qty", Qty);
con.Open();
cmd.ExecuteNonQuery();
GridView1.DataBind();
BindData();
con.Close();
}
}
}
}
I need to insert this row 4 times in database. 
Francis SusaimichaelRank #466 · 5.4K reputationPosted Dec 22, 2015, 11:35 PM EST
{
// Loop thru it
for (int i = 0; i < NoOfTime; i++)
{
using (SqlConnection con = new SqlConnection("Data Source=xxxxx;Initial Catalog=xxxxx;User ID=xx;Password=xxxxx"))
{
using (SqlCommand cmd = new SqlCommand())
{
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO [Itable1](Num,Code,Qty) VALUES(@Num,@Code,@Qty)";
cmd.Parameters.AddWithValue("@CODE", Code);
cmd.Parameters.AddWithValue("@Num", SlNo);
cmd.Parameters.AddWithValue("@Qty", Qty);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
protected void Button26_Click(object sender, EventArgs e)
{
Control control = null;
if (GridView1.FooterRow != null)
control = GridView1.FooterRow;
else
control = GridView1.Controls[0].Controls[0];
string SlNo = (control.FindControl("txtSlNo") as TextBox).Text;
string Code = (control.FindControl("txtcode") as TextBox).Text;
string Qty = (control.FindControl("txtqty") as TextBox).Text;
RepeatInsertion(Code, SlNo, Qty,4);
GridView1.DataBind();
BindData();
}
Francis SusaimichaelRank #466 · 5.4K reputationPosted Dec 22, 2015, 9:19 PM EST
Francis SusaimichaelRank #466 · 5.4K reputationPosted Dec 22, 2015, 9:38 PM EST
Francis SusaimichaelRank #466 · 5.4K reputationPosted Dec 23, 2015, 1:43 AM EST
Sivajihero Hero99 reputationPosted Dec 22, 2015, 9:25 PM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Dec 22, 2015, 9:30 PM EST
Sivajihero Hero99 reputationPosted Dec 22, 2015, 9:35 PM EST
Sivajihero Hero99 reputationPosted Dec 22, 2015, 10:17 PM EST
Sivajihero Hero99 reputationPosted Dec 23, 2015, 12:29 AM EST