.net开发技术文章devjoy.cn技术文档
try
一起娱乐网01716.com{
zhangyongjun.com开发网
// create a new ADOConnection to the text file through ODBC and an existing Data Source
ADOConnection conn = new ADOConnection("Provider=MSDASQL;DSN=registrations;");
javascript技巧尽在快乐开发 // create a DataSet Command that selects all the records from the registration.txt table (which in this case is a file)
.net开发技术文章
ADODataSetCommand AdoCmd = new ADODataSetCommand("SELECT * FROM registrations.txt", conn);
javascript技巧尽在快乐开发// 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());
zhangyongjun.com开发网count++;
if (count > 15)
javascript技巧尽在快乐开发
{
break;
}
}
}
catch(ADOException ae)
{
.net开发技术文章
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.