c# - I want to import data from CSV file to SQL database using Entity Framework -


i want insert data csv file sql table. here code don't know how go further

var readcsv = file.readalltext(filepath); string[] csvfilerecord = readcsv.split('\n');  foreach (var row in csvfilerecord) {   if (!string.isnullorempty(row))   {     foreach (var cell in row.split(','))     {       var cards = new cards       {         //what here assign data each column        };     }   } } 

here csv file data

 12345,cvv,18-april,name,country,address,state,city,dob,zipcode,phone,email,10 12345,cvv,18-april,name,country,address,state,city,dob,zipcode,phone,email,10 

class definition

        public string nummber { get; set; }     public string cvv { get; set; }     public string expdate { get; set; }     public string name { get; set; }     public string country { get; set; }     public string address { get; set; }     public string state { get; set; }     public string dob { get; set; } 

var readcsv = file.readalltext(filepath); string[] csvfilerecord = readcsv.split('\n');  foreach (var row in csvfilerecord) {   if (!string.isnullorempty(row))   {     var cells = row.split(','))     var card = new cards       {          number = cells[0], // number in first cell          cvv = cells[1],   // cvv in second cell          // ...       };   } } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -