Datagridview Cell selected value insert into sqlserver
<p>I have a form with datagridview tools so i am getting data from other form datagridview in first form datagridview and insert data into sqlserver database from first form datagridview.
First form datagridview column names are 
ItemName,quantity,amount etc,which are get from other form datagridview now i want to insert Itemcode against ItemName column from first datagridview rows but i am unable to do this.</p>

<pre><code> private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
    {

        if (ActiveControl == dataGridView1 &amp;&amp; dataGridView1.CurrentCell == dataGridView1.CurrentRow.Cells[0]) // datagridview first cell enter event
        {
            ItemList fc = new ItemList() { OwnerForm = this }; 
            fc.ShowDialog(this);
            dataGridView1.CurrentRow.Cells[0].Value = ItemName;
            dataGridView1.CurrentRow.Cells[4].Value = Item_MRP;
            dataGridView1.CurrentRow.Cells[5].Value = Item_Purchase;

               }
    }
     private void button1_Click(object sender, EventArgs e)
    {
        try { 
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=mateenwin;User ID=sa;Password=123");
        conn.Open();
        SqlCommand commandd = new SqlCommand("SELECT MAX(Pur_Invoice_No)+1  FROM purchase", conn);
        int InvoiceNo = Convert.ToInt32(commandd.ExecuteScalar());

        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            if (row.IsNewRow) continue;

            SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=mateenwin; User id=sa; password=123");
            SqlCommand command = new SqlCommand("Insert into purchase (Pur_Invoice_No,Pur_Payment_Type_ID, Supplier_Bill_No,Supplier_ID,Item_Code,Pur_Item_Batch_No,Item_Batch_Expiry,Pur_Item_PackQuantity,Purchase_Pack_Price,Discount_Percentage,Extra_Discount_Percentage,MRP_Final,Login_ID,Pur_Entry_Date) values ('" + InvoiceNo + "','" + this.comboBox1.SelectedValue + "','" + this.textBox2.Text + "','" + this.comboBox2.SelectedValue + "','" + row.Cells[0].Value + "','" + row.Cells[1].Value + "','" + row.Cells[2].Value + "','" + row.Cells[3].Value + "','" + row.Cells[5].Value + "','" + row.Cells[6].Value + "','" + row.Cells[7].Value + "','" + row.Cells[4].Value + "','" + this.comboBox3.Text + "',  GetDate())", con);
            con.Open();


            using (con)
            {

                command.ExecuteNonQuery();
            }

        }
            MessageBox.Show("Invoice successfully Saved");
            dataGridView1.Focus();
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
</code></pre>