P
Pete Wright
Ok, I sense some confusion with the world of ADO.NET
First up, if you have a comma delimited text file you can read that into a
DataSet quite easily, in principle anyway. But, you have a database now, so
let's work with that.
First thing you are going to want is a connection to the database. Now, I'm
going to assume that you have SQL Server database, but the same principles
apply, just use OleDb whereever you see me using Sql (ie SqlConnection
becomes OleDbConnection). You may need to change the connection string as
well - the bit used in creating the connection. Take a look at the MSDN help
with Visual Studio for pointers on this (Its late and I'm sitting on the
couch miles away from a book)
Ok - so creating a connection
Dim myConnection as SqlConnection = new SqlConnection("Data
Source=localhost;Initial catalog=mydatabase;Integrated Security=true")
With a connection created, you'll need a data adapter - some method of
getting information out of the database and into a dataset
Dim myAdapter as SqlDataAdapter = new SqlDataAdapter( myConnection, "Select
* from myTable");
Now all you need is a DataSet that the data adapter can fill. e.g
Dim myDataSet as DataSet = new DataSet();
myAdapter.Fill( myDataSet, "mytable");
At this point you'll have a single table in the dataset which you can get at
with
myDataSet.Tables("myTable")
and within the table you have rows that you can 'iterate' through with a
foreach loop. For example
Dim myRow as DataRow
for each myRow in myDataSet.Tables("myTable")
:
: Do something with myRow here
next
You should probably look at MSDN for ADO.NET tutorials to get up to speed
with all the terms and how all the objects etc work together.
Hope that helps,
--
Peter Wright
Author of ADO.NET Novice To Pro, from Apress Inc.
_____________________________
First up, if you have a comma delimited text file you can read that into a
DataSet quite easily, in principle anyway. But, you have a database now, so
let's work with that.
First thing you are going to want is a connection to the database. Now, I'm
going to assume that you have SQL Server database, but the same principles
apply, just use OleDb whereever you see me using Sql (ie SqlConnection
becomes OleDbConnection). You may need to change the connection string as
well - the bit used in creating the connection. Take a look at the MSDN help
with Visual Studio for pointers on this (Its late and I'm sitting on the
couch miles away from a book)
Ok - so creating a connection
Dim myConnection as SqlConnection = new SqlConnection("Data
Source=localhost;Initial catalog=mydatabase;Integrated Security=true")
With a connection created, you'll need a data adapter - some method of
getting information out of the database and into a dataset
Dim myAdapter as SqlDataAdapter = new SqlDataAdapter( myConnection, "Select
* from myTable");
Now all you need is a DataSet that the data adapter can fill. e.g
Dim myDataSet as DataSet = new DataSet();
myAdapter.Fill( myDataSet, "mytable");
At this point you'll have a single table in the dataset which you can get at
with
myDataSet.Tables("myTable")
and within the table you have rows that you can 'iterate' through with a
foreach loop. For example
Dim myRow as DataRow
for each myRow in myDataSet.Tables("myTable")
:
: Do something with myRow here
next
You should probably look at MSDN for ADO.NET tutorials to get up to speed
with all the terms and how all the objects etc work together.
Hope that helps,
--
Peter Wright
Author of ADO.NET Novice To Pro, from Apress Inc.
_____________________________