2012-11-19 111 views

回答

0

我得到了解決

using System; 
using System.Drawing; 
using System.Windows.Forms; 
using Excel = Microsoft.Office.Interop.Excel; 

namespace WindowsApplication1 
{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     bgw.RunWorkerAsync(); 
     var myConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\Language_Batch1_OneClick.xls';Extended Properties=Excel 8.0;"); ; 
     var myCommand = new OleDbCommand(); 
     var upCommand = new OleDbCommand(); 
     int i = 0; 
     try 
     { 

      string sql = null; 
      myConnection.Open(); 
      myCommand.Connection = myConnection; 
      sql = "select ANSWER_CODE,Punjabi from [Batch_Lang_1$]"; 
      myCommand.CommandText = sql; 
      var dataReader = myCommand.ExecuteReader(); 

      while (dataReader.Read()) 
      { 
       var langText = Convert.ToBase64String(Encoding.UTF8.GetBytes(dataReader["Punjabi"].ToString())); 
       if (langText.Length >= 1000) 
       { 
        continue; 
       } 
       var ansCode = dataReader["ANSWER_CODE"].ToString(); 
       sql = "update [Batch_Lang_1$] set Punjabi= '" + langText + "' where ANSWER_CODE='" + ansCode + "'"; 
       upCommand.Connection = myConnection; 
       upCommand.CommandText = sql; 
       upCommand.ExecuteNonQuery(); 
       i++; 
      } 
    } 
} 
} 
+0

,這是什麼得到了與UTF8和BASE64辦? –

+0

我仍在爲此工作,但我有一個想法。我有更新我的答案看看。 –

+0

酷我看到..... –