在WEB 页面实现这样一个功能:
我的EXCEL第一列 存储了N多ID(P12345,P12346....),大概2000行左右。此文件在本地。
我有一个页面时是用来查询数据的,想根据这个excel ID 查询 数据。
本地文件和这个页面如何关联 去查询?
我的EXCEL第一列 存储了N多ID(P12345,P12346....),大概2000行左右。此文件在本地。
我有一个页面时是用来查询数据的,想根据这个excel ID 查询 数据。
本地文件和这个页面如何关联 去查询?
调试欢乐多
然后遍历DataSet根据值去查
Dim strReadExcel As String = "select * from " & sheetTabelName
Dim excelConnStr As String = Nothing
excelConnStr = OleDbHelper.CreateExcelConnectionString(filePath, OleDbHelper.AccessMode.Export, OleDbHelper.FirstRowIsTitle.Yes) ' Get data from excel or csv
Dim dr as DataReader= OleDbHelper.ExecuteReader(excelConnStr, CommandType.Text, strReadExcel)
if (dr.Read())
{
}
OleDbConnection xlsConn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath("PList.xls") + "; Extended Properties = 'Excel 8.0; HDR=YES; IMEX=1'");
xlsConn.Open(); string xlsSQL = "select * from [Sheet1] where [id]='xxx'";
OleDbCommand xlsCmd = new OleDbCommand(xlsSQL, xlsConn);
OleDbDataReader dr = xlsCmd.ExecuteReader(); while (dr.Read())
{
string v1 = (dr[0].ToString().Trim() == "") ? "x" : dr[0].ToString // 取第0列的值赋给v1
}如果网页不在本地,那你要写一个上传的代码将excel上传到服务器再用以上方法操作即可。
即便不保存到数据库,
也需要遍历Excel比对筛选条件。
我已经实现了导入到Dataset,也能绑定到控件里。
还有一个疑问,我dataset 里存储的都是ID。
我想用 select * from table where productid in(dataset里的所有ID)
请问怎么做?
select * from table where productid in(dataset里的所有ID)我现在返回的是ds对象,请问我怎么做?
dataset里的所有ID 怎么变成 真正的所有ID 现在是对象啊。。
foreach(DataRow row in ds.Tables[0].Rows)
{
string id= row["id"].ToString();
//你的操作
}
bool isContains = false;
foreach (DataRow r in ds.Tables["tableName"].Rows)
{
if ((string)r["productid "] == "productid")
{
isContains = true;
break;
}
}
string strid;
foreach(DataRow row in ds.Tables[0].Rows)
{
strid+= row["id"].ToString()+',';
//你的操作
}string sql="select * from table where productid in("+strid+")";
DataSet ds=new DataSet ();
foreach(DataRow row in ds.Tables[0].Rows)
{
string id= row["id"].ToString();
//你的操作
}
楼上的哥们,我excel 是1列的 ,2000多行数据 取DataRow row in ds.Tables[0].Rows 还是Columns?
我用Columns怎么就能取1条?
以上基本解决 还有一个问题,如果我excel 的列 没有列名, 直接以PID123123开头怎么办?
不为ID你导入到Dataset的时候你自己设置Dataset 里面的table 列名为ID!!!
{
string str = row[0].ToString();
}
这样吧 你就不用去知道他的列名了!!!