Click here to Skip to main content
15,887,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
These csv file are having different columns and i want to add the datas into mssql db using mvc architecture, i tried using the normal insert statement in the class file, but what if the columns are not the same in all the files?

What I have tried:

 cmd.CommandText = "insert into CDRReportView Values ('" + Convert.ToInt64(item.cdrRecordType) + "','" + Convert.ToInt64(item.globalCallID_callManagerId) + "','"
                                        + Convert.ToInt64(item.globalCallID_callId) + "','" + Convert.ToInt64(item.origLegCallIdentifier) + "' , '"
                                           + Convert.ToInt64(item.dateTimeOrigination) + "','" + Convert.ToInt64(item.origNodeId) + "','"
+ Convert.ToInt64(item.origSpan) + "' ,'" + Convert.ToInt64(item.origIpAddr) + "','" + item.callingPartyNumber + "' ,'"
+ item.callingPartyUnicodeLoginUserID + "','" + Convert.ToInt64(item.origCause_location) + "','"
Posted
Updated 31-Oct-17 23:10pm

1 solution

The chances of your code succeeding with those statements is not high. Start by extracting the data from the csv into proper groups of items. Make sure that you validate each item as you read it in; your code above will just fail if any item is not a valid number. Once you have all the items read in then you can create a proper INSERT statement, using parameters rather than trying to concatenate integers into strings.
 
Share this answer
 

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