1
Answer

External table is not in the expected format.

  1. csv File Upload In mysql database in wamp server 

  2. how this error Clear..
  3. External table is not in the expected format.
  4. //choose path    
  5. private void button1_Click(object sender, EventArgs e)  
  6.     {  
  7.         OpenFileDialog dlg = new OpenFileDialog();  
  8.         dlg.Filter = "Text files | *.csv";  
  9.         if (dlg.ShowDialog() == DialogResult.OK)  
  10.         {  
  11.             string fileName;  
  12.             fileName = dlg.FileName;  
  13.             txtFileName.Text = fileName;  
  14.         }  
  15.     }  
  16. //submit button
  17.     private void button2_Click(object sender, EventArgs e)  
  18.     {  
  19.         if (txtFileName.Text != "")  
  20.         {  
  21.             string path = txtFileName.Text;  
  22.             string id = "";  
  23.             string pimage = "";  
  24.             string cate = "";  
  25.             string subcat = "";  
  26.             string pcode = "";  
  27.             string peng = "";  
  28.             string ptam = "";  
  29.             string barcode = "";  
  30.             string unit = "";  
  31.             string promrp = "";  
  32.             string procast = "";  
  33.             string pprice = "";  
  34.             string aqty = "";  
  35.             string alertqty = "";  
  36.             string pdetail = "";  
  37.             string tax = "";  
  38.             string mdate = "";  
  39.             string edate = "";  
  40.   
  41.             OleDbConnection my_con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");  
  42.             my_con.Open();  
  43.   External table is not in the expected format.//this line error throw 
  44.             OleDbCommand icmd = new OleDbCommand("SELECT * FROM [dataGridView1_Data$]", my_con);  
  45.   
  46.             OleDbDataReader dr = icmd.ExecuteReader();  
  47.             while (dr.Read())  
  48.             {  
  49.                 id = dr[0].ToString();  
  50.                 pimage = dr[1].ToString();  
  51.                 cate = dr[2].ToString();  
  52.                 subcat = dr[3].ToString();  
  53.                 pcode = dr[4].ToString();  
  54.                 peng = dr[5].ToString();  
  55.                 ptam = dr[6].ToString();  
  56.                 barcode = dr[7].ToString();  
  57.                 unit = dr[8].ToString();  
  58.                 promrp = dr[9].ToString();  
  59.                 procast = dr[10].ToString();  
  60.                 pprice = dr[11].ToString();  
  61.                 aqty = dr[12].ToString();  
  62.                 alertqty = dr[13].ToString();  
  63.                 pdetail = dr[14].ToString();  
  64.                 tax = dr[15].ToString();  
  65.                 mdate = dr[16].ToString();  
  66.                 edate = dr[17].ToString();  
  67.   
  68.                 MySqlConnection con = new MySqlConnection("SERVER=localhost;" +  
  69.                     "DATABASE=shop_management;" +  
  70.                     "UID=root;" +  
  71.                     "PASSWORD=;");  
  72.                 con.Open();  
  73.   
  74.                 MySqlCommand icmmd = new MySqlCommand("INSERT INTO add_product(id,product_image,category,sub_category,product_code,product_english, product_tamil,  barcode,unit,product_mrp,product_cost,product_price,available_quantity,alert_quantity,product_detail,tax,man_date,exp_date)VALUES(@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n,@o,@p,@q,@r)", con);  
  75.                 icmmd.Parameters.AddWithValue("a", id);  
  76.                 icmmd.Parameters.AddWithValue("b", pimage);  
  77.                 icmmd.Parameters.AddWithValue("c", cate);  
  78.                 icmmd.Parameters.AddWithValue("d", subcat);  
  79.                 icmmd.Parameters.AddWithValue("e", pcode);  
  80.                 icmmd.Parameters.AddWithValue("f", peng);  
  81.                 icmmd.Parameters.AddWithValue("g", ptam);  
  82.                 icmmd.Parameters.AddWithValue("h", barcode);  
  83.                 icmmd.Parameters.AddWithValue("i", unit);  
  84.                 icmmd.Parameters.AddWithValue("j", promrp);  
  85.                 icmmd.Parameters.AddWithValue("k", procast);  
  86.                 icmmd.Parameters.AddWithValue("l", pprice);  
  87.                 icmmd.Parameters.AddWithValue("m", aqty);  
  88.                 icmmd.Parameters.AddWithValue("n", alertqty);  
  89.                 icmmd.Parameters.AddWithValue("o", pdetail);  
  90.                 icmmd.Parameters.AddWithValue("p", tax);  
  91.                 icmmd.Parameters.AddWithValue("q", mdate);  
  92.                 icmmd.Parameters.AddWithValue("r", edate);  
  93.                 icmmd.ExecuteNonQuery();  
  94.                 con.Close();  
  95.             }  
  96.             MessageBox.Show("data Imported");  
  97.             txtFileName.Text = "";  
  98.         }  
  99.         else if (txtFileName.Text == "")  
  100.         {  
  101.   
  102.         }  
  103.   
  104.     }  
  105.   
  106. }  

Answers (1)