oldb读取txt文件

liuwei19860906 2010-08-17 09:55:39
用oldb读取txt文件时怎么加条件。。。
txt文件内容如下
怎么根据时间来读取。
2010-7-27 8:58:35,0.005,0,0.003,0,0.001,0,0.008,0,0.015,0
2010-7-27 8:58:36,0.005,0,0.002,0,0.002,0,0.008,0,0.016,0
2010-7-27 8:58:37,0.005,0,0.002,0,0.002,0,0.008,0,0.015,0
2010-7-27 8:58:38,0.005,0,0.002,0,0.002,0,0.008,0,0.016,0
2010-7-27 8:58:39,0.004,0,0.003,0,0.001,0,0.008,0,0.015,0
2010-7-27 8:58:40,0.005,0,0.003,0,0.002,0,0.008,0,0.015,0
2010-7-27 8:58:41,0.005,0,0.003,0,0.002,0,0.008,0,0.015,0
2010-7-27 8:58:42,0.005,0,0.002,0,0.002,0,0.007,0,0.015,0
2010-7-27 8:58:43,0.005,0,0.002,0,0.002,0,0.008,0,0.016,0
2010-7-27 8:58:44,0.005,0,0.002,0,0.002,0,0.008,0,0.016,0


string sql = "select * from " + filename ;
string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Text;'";//HDR=No;FMT=Delimited;

OleDbConnection con = new OleDbConnection(conStr);
con.Open();
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand = cmd;
DataSet ds = new DataSet();
oda.Fill(ds);


select 中where 怎么写?
...全文
142 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2010-08-17
  • 打赏
  • 举报
回复
下面的代码可以告诉你,字段名称是什么
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString;
string SQLString;
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~") + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\"";
SQLString = "Select * from a.txt";
System.Data.OleDb.OleDbConnection ConnectionText = new System.Data.OleDb.OleDbConnection();
ConnectionText.ConnectionString = ConnectionString;
ConnectionText.Open();
System.Data.OleDb.OleDbDataAdapter AdapterText = new System.Data.OleDb.OleDbDataAdapter(SQLString, ConnectionText);
System.Data.DataSet DataSetText = new System.Data.DataSet("TextFiles");
AdapterText.Fill(DataSetText, "TextFile");
GridView1.DataSource = DataSetText;
GridView1.DataBind();
ConnectionText.Close();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" >
<div>

</div>
<asp:GridView ID="GridView1" runat="server" ShowHeader="True">
</asp:GridView>
</form>
</body>
</html>
孟子E章 2010-08-17
  • 打赏
  • 举报
回复
我也是显示出来表头,然后测试的
liuwei19860906 2010-08-17
  • 打赏
  • 举报
回复
我msdn都查遍了都没查着 你在哪里查的。。。
hujun4561812 2010-08-17
  • 打赏
  • 举报
回复
这样

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~") + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\"";
SQLString = "Select * from a.txt Where F2=0.004";
因为你的数据没有表头。使用HDR=No
liuwei19860906 2010-08-17
  • 打赏
  • 举报
回复
牛人
谢谢!~
孟子E章 2010-08-17
  • 打赏
  • 举报
回复
看显示出来的日期格式,有的机器显示出来的是这种格式2010/7/27 8:58:37
孟子E章 2010-08-17
  • 打赏
  • 举报
回复
F1=#2010/7/27 8:58:37#

or

F1=#2010-7-27 8:58:35#
liuwei19860906 2010-08-17
  • 打赏
  • 举报
回复
提示操作符丢失
liuwei19860906 2010-08-17
  • 打赏
  • 举报
回复
F2=0.004
可以

怎么F1=2010-7-27 8:58:35就报错?
孟子E章 2010-08-17
  • 打赏
  • 举报
回复
这样

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~") + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\"";
SQLString = "Select * from a.txt Where F2=0.004";
因为你的数据没有表头。使用HDR=No
liuwei19860906 2010-08-17
  • 打赏
  • 举报
回复
我想要的是sql 中 的where 条件怎么写 根据时间读的那种
liuwei19860906 2010-08-17
  • 打赏
  • 举报
回复
1楼,我只能说我不懂你。。。。 你这个是什么意思??
chazikai24 2010-08-17
  • 打赏
  • 举报
回复
SELECT * FROM [{0}]

110,577

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧