CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2000
    Posts
    670

    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?

  2. #2
    Join Date
    Dec 2002
    Location
    Myanmar(Burma)
    Posts
    19

    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

  3. #3
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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
  •  





Click Here to Expand Forum to Full Width

Featured