Click here to Skip to main content
12,399,975 members (48,867 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASM MySQL
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)";
        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 LOCAL INFILE " + path + " INSERT INTO TABLE sla1 FIELDS TERMINATED BY ',' LINES TERMINATED BY ' \r\n' IGNORE 2 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();
        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 LOCAL INFILE " + path + " INSERT INTO TABLE sla1 FIELDS TERMINATED BY ',' LINES TERMINATED BY ' \r\n' IGNORE 2 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>");
                    
            
        ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language="'javascript'">alert('File uploaded Successfully ')</script>");
                    
        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>");
                    }}}
here insquery inserted.but myCUpload i not inserted......
Give again folling error.....
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 TERMINATED' at line 1
Posted 19-Apr-13 0:14am
Updated 19-Apr-13 0:23am
v2
Comments
Prasad Khandekar 19-Apr-13 6:29am
   
I can see a space character before \r\n. Tyr removing that.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2016
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