C#操作Excel时候提示“索引(从零开始)必须大于或等于零,且小于参数列表的大小”。
代码如下:stringmac=MactextBox.Text.Trim();stringgujian=FirmWaretextBox.Text.Trim();string...
代码如下:
string mac = MactextBox.Text.Trim();
string gujian = FirmWaretextBox.Text.Trim();
string Pib = PibtextBox.Text.Trim();
string HFID = HFIDtextBox.Text.Trim();
string name = biaomingtextBox.Text.Trim();
DataSet ds;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Extended Properties=Excel 8.0;" +
"data source=" + SavePathtextBox.Text.Trim();
OleDbConnection myConn = new OleDbConnection(strCon);
myConn.Open();
string sql = string.Format("insert into ["+name+"$] (B,C) values ('{1}','{2}')", gujian,Pib);
OleDbCommand cmd = new OleDbCommand(sql,myConn);
cmd.ExecuteNonQuery();
myConn.Close();
请问是什么原因。 展开
string mac = MactextBox.Text.Trim();
string gujian = FirmWaretextBox.Text.Trim();
string Pib = PibtextBox.Text.Trim();
string HFID = HFIDtextBox.Text.Trim();
string name = biaomingtextBox.Text.Trim();
DataSet ds;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Extended Properties=Excel 8.0;" +
"data source=" + SavePathtextBox.Text.Trim();
OleDbConnection myConn = new OleDbConnection(strCon);
myConn.Open();
string sql = string.Format("insert into ["+name+"$] (B,C) values ('{1}','{2}')", gujian,Pib);
OleDbCommand cmd = new OleDbCommand(sql,myConn);
cmd.ExecuteNonQuery();
myConn.Close();
请问是什么原因。 展开
1个回答
展开全部
string sql = string.Format("insert into ["+name+"$] (B,C) values ('{1}','{2}')", gujian,Pib);
改成
string sql = string.Format("insert into ["+name+"$] (B,C) values ('{0}','{1}')", gujian,Pib);
索引(从零开始)必须大于或等于零,且小于参数列表的大小
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询