18
Answers

how to add more than one record adding in to database

Photo of Kobinath Ram

Kobinath Ram

7y
408
1
i tried below code.but i could add one row record only added in to mysql database. i entered three rows records but only one row records only added.what is the problem of the below code please any one can help me this problem.
 
 
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "insert into salesproductnew(salesid,productname,qty,price,grosstotal)values(@salesid,@productname,@qty,@price,@grosstotal)";
cmd.Parameters.AddWithValue("@salesid", lbinvoice.Text);
cmd.Parameters.AddWithValue("@productname", dataGridView1.Rows[i].Cells[2].Value);
cmd.Parameters.AddWithValue("@qty", dataGridView1.Rows[i].Cells[3].Value);
cmd.Parameters.AddWithValue("@price", dataGridView1.Rows[i].Cells[4].Value);
cmd.Parameters.AddWithValue("@grosstotal", dataGridView1.Rows[i].Cells[5].Value);
con.Open(); cmd.ExecuteNonQuery();
MessageBox.Show("Record added ............."); con.Close();

Answers (18)

0
Photo of Manish Dwivedi
NA 8.3k 1.2m 12y
Hi Ashish,

If you want to remove anchor tag, then change little bit your regular expression like that

string sample = "<a href=\"http://test.com\">LoremIpsum.Net</a> is.";
  string re = @"<a [^>]+>(.*?)<\/a>(.*?)";

  //sample = Regex.Replace(sample, re, "$1");
  sample = Regex.Replace(sample, re,"$2");

Thanks