|
-
February 3rd, 2003, 04:00 AM
#1
How can I get data from mdb file in C#.net
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?
-
February 3rd, 2003, 04:30 AM
#2
Small help...
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 ....
Enjoy it
coolrock
-
February 3rd, 2003, 10:43 PM
#3
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();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|