Click to See Complete Forum and Search --> : How can I get data from mdb file in C#.net


RY33
February 3rd, 2003, 03:00 AM
How can I get data from mdb file in C#.net?
How do I write my connection to the mdb file, and what do I do next?

COOLROCK
February 3rd, 2003, 03:30 AM
Dear Friend,
I am sorry that I can't explain all things you want cause it's the whole concept of ADO.net.I want to give you an advise that pls read Ado.net chapter to understand
......DataSet
......DataAdapter
......DataProvider(OleDb.net and SQL Server .net providers)
and others ...


Sample connection string with SqlConnection From MS C#.net Ebook
////
SqlConnection conn = new SqlConnection();
string sConnString = "data source=(local);initial catalog=pubs;" +
"user id=sa;password=;";
conn.ConnectionString = sConnString;
//


Sample datareader From MS C#.net Ebook


SqlCommand cmd = new SqlCommand("SELECT * FROM authors");



SqlDataReader rdr = cmd.ExecuteReader();

While(rdr.Read())
{
string firstCol = rdr.GetSqlString(0);
int secondCol = rdr.GetSqlInt32(1);
//Get other columns using the Get methods
//and take action.

}


a lot...


I am sorry that I can't explain the whole chapter.Pls read Ado.net chapter ....




:D Enjoy it

pareshgh
February 3rd, 2003, 09:43 PM
for SqlConnection you will need a SqlClient.
how ever OleDb... commands are usefull when ODBC connection is available.




///herez the function to read the data
public void ReadMyData(string myConnString)
{
string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders";
OleDbConnection myConnection = new OleDbConnection(myConnString);
OleDbCommand myCommand = new OleDbCommand(mySelectQuery,myConnection);
myConnection.Open();
OleDbDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
}
}
finally
{
// always call Close when done reading.
myReader.Close();
// always call Close when done reading.
myConnection.Close();
}
}

/// insert row
public void InsertRow(string myConnectionString)
{
// If the connection string is null, use a default.
if(myConnectionString == "")
{
myConnectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;" +
"Integrated Security=SSPI;";
}
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}