|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
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. 返回类别: 教程 上一教程: ASP与数据库应用(给初学者) 下一教程: [ASP]使用类,实现模块化 您可以阅读与"ADO.NET:使用ADO.NET连接文本文件"相关的教程: · ADO连接数据库字符串大全(VP,EXCEL,文本,SYBASE,.NET等) · 用ADODB.STREAM代替FSO读取文本文件 · ASP中文本文件与数据库文件的数据交换 · 怎样读取一个文本文件的内容 · 从文本文件中读取信息并存储入数据库 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |