Click here to Skip to main content
15,913,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys

I need to upload a .csv File into My Sql database using File Upload in ASP.NET?

Please Help Me!!!

Thanks and Regards
harsha :)
Posted
Comments
Sandeep Mewara 4-Jul-12 4:25am    
And any effort from your side? Where are you stuck?
Harsha Dev 4-Jul-12 8:22am    
//string filepath = @"C:\Documents and Settings\HPFS.HPFS\Desktop\rajmal.csv";
string file = FileUpload1.PostedFile.FileName;
file = Path.GetFileName(file);
string filepath = Server.MapPath("~/csv/")+file;
FileUpload1.SaveAs(filepath);
StreamReader sr = new StreamReader(filepath);
string line = sr.ReadLine();
string[] value = line.Split(';');
DataTable dt = new DataTable();
DataRow row;
foreach (string dc in value)
{
dt.Columns.Add(new DataColumn(dc));
}
while ( !sr.EndOfStream )
{
value = sr.ReadLine().Split(';');
if(value.Length == dt.Columns.Count)
{
row = dt.NewRow();
row.ItemArray = value;
dt.Rows.Add(row);
}
}


SqlBulkCopy bc = new SqlBulkCopy(sc.ConnectionString, SqlBulkCopyOptions.TableLock);

bc.DestinationTableName = "company";

bc.BatchSize = dt.Rows.Count;

sc.Open();

bc.WriteToServer(dt);

Response.Write("Ok");

bc.Close();

sc.Close();

Hi its working in SQL SQL Server but not mysql server please help!!! :)

1 solution

Hi, please see this two most related discussion:
1,http://forums.asp.net/t/1691278.aspx/1[^]
2,http://stackoverflow.com/questions/10321698/csv-to-mysql-via-asp-net[^]
Best Regards
 
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