Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MySQL
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'D:\Book1111.csv INSERT INTO TABLE sla1 FIELDS TERMINATED BY ',' LINES TERMINAT' at line 1
my code.........
string path = FileUpload1.PostedFile.FileName;
string ext = Path.GetExtension(path);
string contenttype = string.Empty;
if (!FileUpload1.HasFile)
{
 
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Please select a file')</script>"); //if file uploader has no file selected
 
}
else if (FileUpload1.HasFile)
{
try
{
switch (ext)
{
case ".csv":
 
contenttype = "application/vnd.ms-excel";
 
break;
}
string year = ddlyear.SelectedItem.ToString();
string month = ddlmonth.SelectedItem.ToString();
MySqlConnection exclecon = new MySqlConnection("Server=Localhost;DataBase=password1;user=root;password=nectar");
string insquery = "INSERT INTO sla (month, year, contenttype) VALUES(@month, @year, @contenttype)";
string uploadQry = "LOAD DATA INFILE " + path + " INSERT INTO TABLE sla1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES";
MySqlCommand mycom = new MySqlCommand(insquery, exclecon);
mycom.Parameters.AddWithValue("@month", month);
mycom.Parameters.AddWithValue("@year", year);
mycom.Parameters.Add("@contenttype", MySqlDbType.VarChar).Value = contenttype;
 
MySqlCommand myCUpload = new MySqlCommand(uploadQry, exclecon);
exclecon.Open();
mycom.ExecuteNonQuery();
myCUpload.ExecuteNonQuery();

ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('File uploaded Successfully ')</script>");

}

catch (Exception ex)
{
Label4.Text = "Error: " + ex.Message.ToString();
 
}
}
}
Posted 19-Apr-13 2:13am
Comments
Prasad Khandekar at 19-Apr-13 7:16am
   
Why post it again?
ThePhantomUpvoter at 19-Apr-13 7:26am
   
I think 6 postings of the same thing over and over qualifies as abuse.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

1) Enclose the path in your query with single quotes.
string uploadQry = "LOAD DATA INFILE '" + path + "' INSERT INTO TABLE sla1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES";
2) Remove INSERT command from your Query.
string uploadQry = "LOAD DATA INFILE '" + path + "' INTO TABLE sla1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES";
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi..
 
Write the blow code on mysql command promt window also.
once try it.
 
>>LOAD DATA LOCAL INFILE "filepath" INTO TABLE databasename.tablename FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
 
its may helpful for u!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 Sergey Alexandrovich Kryukov 195
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100