public DataTable ReturnTable() { dr = dt.NewRow(); dr["TicketID"] = lblTicketID.Text; dr["Service_Id"] = lblServiceID.Text; dr["Description"] = cmbService.SelectedValue; dr["Duration"] = txtDuration.Text; dr["Price"] = txtPrice.Text; dr["Discount"] = txtDiscount.Text; dr["Totals"] = (Convert.ToInt32(txtPrice.Text) - Convert.ToInt32(txtDiscount.Text)).ToString(); dt.Rows.Add(dr); gvBillGenerate.DataSource = dt; ClearControls(); return dt; } private void Form_Load(object sender, EventArgs e) { dt.Columns.Add(new DataColumn("TicketID", typeof(int))); dt.Columns.Add(new DataColumn("Service_Id", typeof(string))); dt.Columns.Add(new DataColumn("Description", typeof(string))); dt.Columns.Add(new DataColumn("Duration", typeof(int))); dt.Columns.Add(new DataColumn("Price", typeof(int))); dt.Columns.Add(new DataColumn("Discount", typeof(int))); dt.Columns.Add(new DataColumn("Totals", typeof(decimal))); dt.Columns.Add(new DataColumn("GrandTotal", typeof(decimal))); } private void btnAddServices_Click(object sender, EventArgs e) { dt=ReturnTable(); } private void btnSave_Click(object sender, EventArgs e) { try { con = new SqlConnection(strconn); com = new SqlCommand(); com.Connection = con; con.Open(); using (SqlBulkCopy s = new SqlBulkCopy(con)) { s.DestinationTableName = dt.TableName; foreach (var column in dt.Columns) s.ColumnMappings.Add(column.ToString(), column.ToString()); s.WriteToServer(dt); MessageBox.Show("Are you sure to save these records ?", "Save Record ", MessageBoxButtons.YesNo, MessageBoxIcon.Information); } con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)