这是我使用的语句:
string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = 'D:/test1.xls';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
if (myDs.Tables[0].Rows.Count > 0)
{
string strSql = "";
string CnnStr = "server=server;uid=IUSR_ZHAO;pwd=33800722;Database=TNet";
SqlConnection conn = new SqlConnection(CnnStr);
conn.Open();
SqlCommand myCmd = null;
for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
{
strSql = "Insert Into T_Expert(Name,sex,E-Mail,Address,Telephone,JobTitle,age,Company,Specialty)values ('";
strSql+=myDs.Tables[0].Rows[i].ItemArray[0].ToString()+"','";
strSql += myDs.Tables[0].Rows[i].ItemArray[1].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[2].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[3].ToString() + "')";
strSql += myDs.Tables[0].Rows[i].ItemArray[4].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[5].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[6].ToString() + "')";
strSql += myDs.Tables[0].Rows[i].ItemArray[7].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[8].ToString() + "')"; try
{
myCmd = new SqlCommand(strSql,conn);
myCmd.ExecuteNonQuery();
Response.Write("<script>alert('Succeed')</script>");
}
catch
{
Label1.Text="<script>alert('Failed');</script>";
}
}
conn.Close();
conn.Dispose(); }
但是每次都是返回“Failed!”上面的语句有错误吗?
string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = 'D:/test1.xls';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
if (myDs.Tables[0].Rows.Count > 0)
{
string strSql = "";
string CnnStr = "server=server;uid=IUSR_ZHAO;pwd=33800722;Database=TNet";
SqlConnection conn = new SqlConnection(CnnStr);
conn.Open();
SqlCommand myCmd = null;
for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
{
strSql = "Insert Into T_Expert(Name,sex,E-Mail,Address,Telephone,JobTitle,age,Company,Specialty)values ('";
strSql+=myDs.Tables[0].Rows[i].ItemArray[0].ToString()+"','";
strSql += myDs.Tables[0].Rows[i].ItemArray[1].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[2].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[3].ToString() + "')";
strSql += myDs.Tables[0].Rows[i].ItemArray[4].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[5].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[6].ToString() + "')";
strSql += myDs.Tables[0].Rows[i].ItemArray[7].ToString() + "','";
strSql += myDs.Tables[0].Rows[i].ItemArray[8].ToString() + "')"; try
{
myCmd = new SqlCommand(strSql,conn);
myCmd.ExecuteNonQuery();
Response.Write("<script>alert('Succeed')</script>");
}
catch
{
Label1.Text="<script>alert('Failed');</script>";
}
}
conn.Close();
conn.Dispose(); }
但是每次都是返回“Failed!”上面的语句有错误吗?
解决方案 »
- 我有一个批量更新和插入的问题,希望大侠们帮帮忙
- 高分求ASP.NET教程
- 请帮忙看看第三方接口的错误信息MCR instance is not available是什么意思
- (高分求救)谁做过环境检测方面的网站规划啊
- 求助:登入出现这种情况是什么原因??
- 请问:如何在VS2003中使用GridView控件?
- 怎样取得oledbconnection 的数据源的相对路径?
- 如何控制DataGrid的行高?在线等,马上结!
- 我們公司用asp.net寫了一個B/S結構的ERP項目,想把它放到internel網上,但不知怎麼樣做?
- 急~~,关于装完Exchange 2000 后ASP.NET应用程序无法发布的问题!
- 服务器上出现应用程序错误 大家帮忙看看这是怎么回事啊
- 请问在ASP.NET里面的MasterPage可以绑定动态内容吗???
Response.Write(myDs.Tables[0].Rows[i].ItemArray[0].ToString());