Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using (DbDataReader dr = command.ExecuteReader())
              {
                  // SQL Server Connection String
                  string sqlConnectionString = "Data Source=ACHRAF\\SQLEXPRESS;Initial Catalog=PFEBD;Integrated Security=True";

                  // Bulk Copy to SQL Server
                  using (SqlBulkCopy bulkCopy =
                             new SqlBulkCopy(sqlConnectionString))
                  {
                      bulkCopy.DestinationTableName = "CDR";
                      bulkCopy.ColumnMappings.Add("RecordFileName", "RecordFileName");
                      bulkCopy.ColumnMappings.Add("Type-of-Recording", "TypeOfRecording");
                      bulkCopy.ColumnMappings.Add("ANumber", "ANumber");
                      bulkCopy.ColumnMappings.Add("BNumber", "BNumber");
                      bulkCopy.ColumnMappings.Add("BNumber-Type", "BNumberType");
                      bulkCopy.ColumnMappings.Add("Who-Pay", "WhoPay");
                      bulkCopy.ColumnMappings.Add("Call-Start-Date", "CallStartDate");
                      bulkCopy.ColumnMappings.Add("Call-Start-Time", "CallStartTime");
                      bulkCopy.ColumnMappings.Add("Call-Duration", "CallDuration");
                      bulkCopy.ColumnMappings.Add("Sample-Type", "SampleType");
                      bulkCopy.ColumnMappings.Add("Outgoing-Route", "OutgoingTrunk");
                      bulkCopy.ColumnMappings.Add("Incoming-Route", "IncommingTrunk");
                      bulkCopy.ColumnMappings.Add("Counter-Number", "CounterNumber");
                      bulkCopy.ColumnMappings.Add("Number-of-Pulse", "NumberofPulse");
                      bulkCopy.ColumnMappings.Add("Cause", "Cause");
                      bulkCopy.ColumnMappings.Add("Location", "Location");
                      bulkCopy.ColumnMappings.Add("Called-Party-Portability-Info", "CalledPartyPortabilityInfo");
                      bulkCopy.ColumnMappings.Add("Call-Reference", "CallReference");
                      bulkCopy.ColumnMappings.Add("Sequence-Number", "SequenceNumber");
                      bulkCopy.ColumnMappings.Add("Network-Call-Reference", "NetworkCallReference");


                      bulkCopy.WriteToServer(dr);//

                  }
              }


What I have tried:

Unable to convert the provided Double type value for the data source to the int type of the specified target column.
Posted
Updated 14-May-18 8:49am

You can use a typecast if you want the default truncate-towards-zero behaviour but that might not work for each business case. Alternatively, you might want to use
Math.Ceiling, Math.Round, Math.Floor etc - although you'll still need a cast afterwards.
Convert.ToInt32(Math.Round(dblValue))

you will need to take care of overflow as int is smaller in range than the double.
 
Share this answer
 
v2
In your query for your reader convert the column to int, then the type will match. Do something like this:

CAST(<some value> AS INT)
 
Share this answer
 
Only Cascade your value for example like C code...
C++
double avg;
print("%lf",avg);
sum  = (int)avg+a;
print("%d",sum);
 
Share this answer
 
v2

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