ADO.NET:使用ADO.NET连接文本文件

滋HWB935dgj

滋HWB935dgj

2016-01-29 18:24

ADO.NET:使用ADO.NET连接文本文件,ADO.NET:使用ADO.NET连接文本文件
  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.


 
展开更多 50%)
分享

猜你喜欢

ADO.NET:使用ADO.NET连接文本文件

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

ADO 与ADO.NET

电脑网络
ADO 与ADO.NET

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

ADO.NET 和 ADO 的比较

电脑网络
ADO.NET 和 ADO 的比较

ADO.NET:ADODataReader类

ASP
ADO.NET:ADODataReader类

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

ADO.NET快速起步

电脑网络
ADO.NET快速起步

ADO.NET学习笔记(二)

电脑网络
ADO.NET学习笔记(二)

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

隐藏在XP中的二十八个秘密武器

隐藏在XP中的二十八个秘密武器

用WPS2000做电子相册三步曲

用WPS2000做电子相册三步曲
下拉加载更多内容 ↓