// DataSet CityDs = Maticsoft.DBUtility.DbHelperSQL.Query("select CityID from City where CityName='" + cityName + "'");
// if (CityDs.Tables[0].Rows.Count > 0)
// {
// int cityId = int.Parse(CityDs.Tables[0].Rows[0][0].ToString());
// mod.CityID = cityId;
// }
// else
// {
// rowError = string.Format(" 在录入失败:{0},{1},{2},{3},{4},{5} 因为在数据库里无法匹配到 {6} <br>", provinceName, cityName, contactPerson, adrress, name, phone, cityName);
// errorInfo += rowError;
// }
// if (rowError.Length > 4)
// {
// error++;
// continue;
// }
// mod.OrderId = 0;
// try
// {
// if (worksheet.Rows[ushort.Parse(1.ToString())].GetCell(ushort.Parse(7.ToString())).Value.ToString() == "排序序号")
// {
// mod.OrderId = int.Parse(worksheet.Rows[ushort.Parse(k.ToString())].GetCell(ushort.Parse(7.ToString())).Value.ToString());
// } // }
// catch (Exception ex)
// { // } // int isInsert = 0;
// try
// {
// if (isHasSelectFile)
// {
// Maticsoft.DBUtility.DbHelperSQL.ExecuteSql("delete AgentInfo");//清空表数据
// isHasSelectFile = false;
// }
// isInsert = bll.Add(mod);
// if (isInsert > 0)
// {
// rows++;
// }
// else
// {
// errorInfo += " 写入数据库时失败!<br>";
// error++;
// continue;
// }
// }
// catch (Exception ex)
// {
// errorInfo += " 写入数据库时发生异常!<br>";
// error++;
// } // }
// } //}
#endregion
[/code]
用这个org.in2bits.MyXls.DLL 就没有问题 但是遍历的列和单元格的顺序都不对应了 真头疼啊
// if (CityDs.Tables[0].Rows.Count > 0)
// {
// int cityId = int.Parse(CityDs.Tables[0].Rows[0][0].ToString());
// mod.CityID = cityId;
// }
// else
// {
// rowError = string.Format(" 在录入失败:{0},{1},{2},{3},{4},{5} 因为在数据库里无法匹配到 {6} <br>", provinceName, cityName, contactPerson, adrress, name, phone, cityName);
// errorInfo += rowError;
// }
// if (rowError.Length > 4)
// {
// error++;
// continue;
// }
// mod.OrderId = 0;
// try
// {
// if (worksheet.Rows[ushort.Parse(1.ToString())].GetCell(ushort.Parse(7.ToString())).Value.ToString() == "排序序号")
// {
// mod.OrderId = int.Parse(worksheet.Rows[ushort.Parse(k.ToString())].GetCell(ushort.Parse(7.ToString())).Value.ToString());
// } // }
// catch (Exception ex)
// { // } // int isInsert = 0;
// try
// {
// if (isHasSelectFile)
// {
// Maticsoft.DBUtility.DbHelperSQL.ExecuteSql("delete AgentInfo");//清空表数据
// isHasSelectFile = false;
// }
// isInsert = bll.Add(mod);
// if (isInsert > 0)
// {
// rows++;
// }
// else
// {
// errorInfo += " 写入数据库时失败!<br>";
// error++;
// continue;
// }
// }
// catch (Exception ex)
// {
// errorInfo += " 写入数据库时发生异常!<br>";
// error++;
// } // }
// } //}
#endregion
[/code]
用这个org.in2bits.MyXls.DLL 就没有问题 但是遍历的列和单元格的顺序都不对应了 真头疼啊
读取excel到dataset我也做过,在本地和服务器都没有问题.using System.Data.OleDb; /// <summary>
/// 根据excel表格返回一个DataSet
/// </summary>
/// <param name="Path">Excel文件的路径</param>
/// <returns>DataSet</returns>
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [sheet1$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, "table1");
conn.Close();
return ds;
}
至:zx75991 以前是可以啊 后来不行的我也想应该不是代码的错因为前段时间是可以的后来不行的 但是人家只要结果 不知道大家有什么替代品没
如果是权限问题, 那么找找有没有通过修改web的配置文件来达到目的