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 SusaimichaelPosted Dec 23, 2015, 4:35 AM
{
// 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 SusaimichaelPosted Dec 23, 2015, 6:43 AM
Sivajihero HeroPosted Dec 23, 2015, 5:29 AM
Sivajihero HeroPosted Dec 23, 2015, 3:17 AM
Francis SusaimichaelPosted Dec 23, 2015, 2:38 AM
Sivajihero HeroPosted Dec 23, 2015, 2:35 AM
Ranjit PowarPosted Dec 23, 2015, 2:30 AM
Sivajihero HeroPosted Dec 23, 2015, 2:25 AM
Francis SusaimichaelPosted Dec 23, 2015, 2:19 AM