test1 test2 test3 test4 test5
a a a a a
a a a a a
a a a a a
a a a a a
a a a a a
a a a a a
という構造のEXCELが名前testで定義されており
このEXCELを以下の通り更新したいのですが、パラメーターエラーが出ます。
using System; using System.Data; using System.Data.OleDb; public partial class ExcelWriter : System.Web.UI.Page { public string exceptions { get; set; } public string exceptions2 { get; set; } public ExcelWriter() { exceptions = ""; exceptions2 = ""; } protected void Page_Load(object sender, EventArgs e) { DataTable dTable = new DataTable(); string path = "C:/Users/user/Desktop/test.xlsx"; string ocnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + "; Extended Properties=" + "\"Excel 12.0;HDR=NO;\""; string strSQL = " UPDATE [sheet1$] SET 'test1' = 'b' ;"; OleDbCommand oCom = new OleDbCommand(); OleDbConnection ocn = new OleDbConnection(); ocn.ConnectionString = ocnStr; ocn.Open(); oCom.Connection = ocn; oCom.CommandText = strSQL; try { oCom.ExecuteNonQuery(); } catch (OleDbException exception) { for (int i = 0; i < exception.Errors.Count; i++) { exceptions = exception.Errors[i].ToString(); exceptions2 = exception.Errors[i].SQLState.ToString(); } } ocn.Close(); } }
どうすれば解決するでしょうか。
回答1件
あなたの回答
tips
プレビュー