关于Webservice中的上传,为什么总是会报错。
总会报:System.Data.OleDb.OleDbException: 无效的 internet 地址。
代码:
[WebMethod]
public string GetQuery(string strPath,string strFilename)
{
string no ="1";
string strConn = "Password=test;User ID=test;Data Source=ACIP008;Initial Catalog=DigitalCampus;Workstation ID=ACIP008;";
SqlConnection cn = new SqlConnection(strConn);
DataSet ds = GetExecleDs(strPath, strFilename, 1); //调用自定义方法
DataRow[] dr = ds.Tables[0].Select(); //定义一个DataRow数组
int rowsNum = ds.Tables[0].Rows.Count;
if (rowsNum != 0)
{
for (int i = 0; i < dr.Length; i++)
{
string code = dr[i]["Code"].ToString();
string name = dr[i]["Name"].ToString();
string sex= dr[i]["Sex"].ToString();
DateTime birthday = Convert.ToDateTime(dr[i]["Birthday"]);
string insertstr = "insert into DC_Student(code,name,sex,birthday) values('" + code + "','" + name + "','" + sex + "','" + birthday + "')";
SqlCommand cmd = new SqlCommand(insertstr, cn);
if (cn.State != ConnectionState.Open)
{
cn.Open();
}
cmd.ExecuteNonQuery();
}
}
cn.Close();
return no;
}
public DataSet GetExecleDs(string strFilenameUrl, string strTable, int intI)
{
//string savePath = Server.MapPath("http://file.acipchina.com/Files/UploadExcel/");
//就是这边地址报错 急急急啊
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilenameUrl + strTable + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [Sheet" + intI + "$]", conn);
odda.Fill(ds, strTable);
return ds;
}
[解决办法]
检查,该地址+ strFilenameUrl + strTable +
是否可以直接打开