当前位置: 首页 > 图文教程 > 网络编程 > ASP > ADO.NET:使用ADO.NET连接文本文件

ASP
利用cookie收藏网站
显示左边的n个字符(自动识别汉字)函数
怎样经由ADO来压缩Microsoft Access数据库
样设置为使用OLEDB连接我的Access数据库?
纯猝使用VBScript来实现加密
ASP.NET:处理session
输入显示框中循环出现文字
关于密码校验
图片循环显现
怎样传送更多的数据在表单中
对ASP脚本源代码进行加密
判断函数是奇数还是偶数
SQL7的image字段的文件下载到客户端
怎样把数据库结构显示出来的源代码
随机访问Recordset的一条记录
利用http组件实现多引擎搜索功能
String添加trim,ltrim,rtrim
ASP创建EXCHANGE用户的一段代码
测字符串长度函数
如何从ACCESS数据库中读取图形(续)

ASP 中的 ADO.NET:使用ADO.NET连接文本文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 29 ::
收藏到网摘: n/a

  try
{
// create a new ADOConnection to the text file through ODBC and an existing Data Source
ADOConnection conn = new ADOConnection("Provider=MSDASQL;DSN=registrations;");
// create a DataSet Command that selects all the records from the registration.txt table (which in this case is a file)
ADODataSetCommand AdoCmd = new ADODataSetCommand("SELECT * FROM registrations.txt", conn);

// fill the dataset with the registration.txt table
AdoCmd.FillDataSet(dataSet1, "registrations.txt");
DataTable ContactTable = dataSet1.Tables[0];
int count = 0;

// loop through each row of the table and fill 15 rows of the listview
foreach (DataRow dr in ContactTable.Rows)
{
listView3.ListItems[count].Text = dr["LastName"].ToString();
listView3.ListItems[count].SetSubItem(0, dr["FirstName"].ToString());
listView3.ListItems[count].SetSubItem(1, dr["Company"].ToString());
listView3.ListItems[count].SetSubItem(2, dr["Address"].ToString());
count++;
if (count > 15)
{
break;
}
}
}
catch(ADOException ae)
{
Console.WriteLine(ae.Message.ToString());
}


That's all there is to it. This should also give you an idea of how to connect to databases through ODBC such as Oracle, Informix, Sybase, or Interbase. All you need to do is set up the appropriate Data Source through the Administration tools and use the code above to access your tables.