广

ASP.NET

  • IOS开发
  • android开发
  • PHP编程
  • JavaScript
  • ASP.NET
  • ASP编程
  • JSP编程
  • Java编程
  • 易语言
  • Ruby编程
  • Perl编程
  • AJAX
  • 正则表达式
  • C语言
  • 编程开发

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

    2018-04-16 10:57:13 次阅读 稿源:互联网
    广告
    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.

    一起学吧部分文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与一起学吧进行文章共享合作。

    广告
    广告
    广告