dipti kate

dipti kate

  • NA
  • 23
  • 12.3k

regarding gridview

Nov 4 2015 1:36 AM
i want to take check rows in gvcheckcontact from gvcontact and then perform update operation on gvcheckcontact and insert gvcheckcontact into database but i could not insert data in database.
i was write code on btnaddcontact like bellow
protected void btnaddcontact_Click(object sender, EventArgs e)
{
foreach (GridViewRow g1 in gvcheckdata.Rows)
{
SqlConnection con = new SqlConnection("Data Source=ANOCRM-PC\\SQLEXPRESS1;Initial Catalog=anosalescrm;Integrated Security=True");
SqlCommand com = new SqlCommand("insert into savetodb select [SrNo] ,[CompanyName],[CompanyWebsite],'" + g1.Cells[0].Text + "' as FirstName,'" + g1.Cells[1].Text + "' as MiddleName,'" + g1.Cells[2].Text + "' as LastName,'" + g1.Cells[4].Text + "' as Title,'" + g1.Cells[3].Text + "' as Email ,'" + g1.Cells[5].Text + "' as DirectPhone,[CorporatePhone],[Fax] ,[Address1],[Address2],[Country] ,[State] ,[City] ,[Countrycode] ,[ZipCode],[Industry] ,[Employees],[Revenue],'" + g1.Cells[8].Text + "'as Result , '" + g1.Cells[9].Text + "' as Comment ,'" + g1.Cells[6].Text + "' as Level,'" + g1.Cells[7].Text + "' as FunctionalArea,[Projectid] ,GETDATE(),'" + Session["MemberId"] + "' as memberid ,null from (select top 1 * from savetodb where CompanyName='" + Session["CompanyName"] + "' and SrNo= " + Session["SrNo"] + "and Projectid= " + Session["projectid"] + ")t", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
Label21.Text = "Records inserted successfully";
}

Answers (6)