Click here to Skip to main content
15,886,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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);
            }
        }



I Getting Error :The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.
Posted
Updated 30-Oct-14 20:56pm
v2
Comments
nainika_ 31-Oct-14 4:28am    
Got the error !
Maciej Los 31-Oct-14 14:50pm    
Great! Please share your solution (and mark as an answer) or delete the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900