private void btnSave_Click(object sender, EventArgs e) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { string StrQuery = @"INSERT INTO finance VALUES ('" + Convert.ToInt32(dataGridView1.Rows[i].Cells["ID"].Value) + "', '" + dataGridView1.Rows[i].Cells["Account Number"].Value + "', '" + dataGridView1.Rows[i].Cells["Bank Name"].Value + "','" + dataGridView1.Rows[i].Cells["Branch Code"].Value + "', '" + dataGridView1.Rows[i].Cells["Student Name"].Value + "', '" + dataGridView1.Rows[i].Cells["Class"].Value + "', '" + dataGridView1.Rows[i].Cells["Section"].Value + "','" + txtDueDate.Text.Trim() + "','" + txtValidityDate.Text.Trim() + "','" + txtNewIssueDate.Text.Trim() + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Registration Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Admission Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Security Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Annual Charges"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Prospectus Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Tuition Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Computer ICT Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Lab Charges"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Arrears"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Safety Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Admission Process Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["ICT Book"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Uniform Fee"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Others"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Fine"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Net Payable"].Value) + "', '" + Convert.ToDecimal(dataGridView1.Rows[i].Cells["Net Payable After Due Date"].Value) + "', '" + dataGridView1.Rows[i].Cells["Status"].Value + "');"; try { using (SqlConnection conn = new SqlConnection(Connection_Properties.GetConnectionString())) { using (SqlCommand comm = new SqlCommand(StrQuery, conn)) { conn.Open(); comm.ExecuteNonQuery(); comm.Clone(); conn.Close(); } } } catch (Exception ee) { MessageBox.Show("All Records Added Successfully.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void con() { SqlConnection con = new SqlConnection(Connection_Properties.GetConnectionString()); }