I keep getting the following error with this code, can anyone put me right on what I'm doing wrong or what I'm missing from my code.
Error:
Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MailPassword System\MailPassword System\Default.aspx.cs 69 43 MailPassword
System
Error 2 Argument 1: cannot convert from 'string' to 'char[]' C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MailPassword System\MailPassword System\Default.aspx.cs 69 60 MailPassword System
Code:
if (CSVImport.HasFile)
{
CSVImport.SaveAs(Server.MapPath("csv\\import.csv"));
string[] records = System.IO.File.ReadAllLines(Server.MapPath("csv\\import.csv"), System.Text.Encoding.Default);
for (int i = 0; i <= records.Length - 1; i++)
{
string[] record = records[i].Split(";");
CreateRecord(record);
}
Response.Write("Succesfully uploaded to sql");
}
else
{
Response.Write("Please input a file");
}
Any pointer would be nice.
Regards
Regards
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
tparky
Member
112 Points
128 Posts
Importing CSV to SQL Server
Aug 12, 2012 08:42 PM|LINK
Hi Guys,
I keep getting the following error with this code, can anyone put me right on what I'm doing wrong or what I'm missing from my code.
Error:
Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MailPassword System\MailPassword System\Default.aspx.cs 69 43 MailPassword System
Error 2 Argument 1: cannot convert from 'string' to 'char[]' C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MailPassword System\MailPassword System\Default.aspx.cs 69 60 MailPassword System
Code:
if (CSVImport.HasFile) { CSVImport.SaveAs(Server.MapPath("csv\\import.csv")); string[] records = System.IO.File.ReadAllLines(Server.MapPath("csv\\import.csv"), System.Text.Encoding.Default); for (int i = 0; i <= records.Length - 1; i++) { string[] record = records[i].Split(";"); CreateRecord(record); } Response.Write("Succesfully uploaded to sql"); } else { Response.Write("Please input a file"); }Any pointer would be nice.
Regards
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education
UstesG
Contributor
2098 Points
449 Posts
Re: Importing CSV to SQL Server
Aug 12, 2012 09:11 PM|LINK
check the value of records[i] before trying to split.
But don't expect me to do your job!
shivv
Participant
1566 Points
283 Posts
Re: Importing CSV to SQL Server
Aug 13, 2012 06:41 AM|LINK
Use single quotes in Split because it takes char not string and double quotes represents string. so it will looks like.
string[] record = records[i].Split(';');tparky
Member
112 Points
128 Posts
Re: Importing CSV to SQL Server
Aug 13, 2012 07:17 PM|LINK
Hi shivv,
Thank you for your reply. I new it had to be something simple like that, it was the only thing that I hadn't tried changing.
Regards
Thomas
Thomas Park
Programming in ASPX and C# build Application on Microsoft .NET Framework 4.0 for Small Business and Education