Sivajihero Hero

Sivajihero Hero

  • NA
  • 105
  • 32.7k

Insert same row in database for multiple times

Dec 23 2015 1:47 AM
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. 

Answers (9)