CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2008
    Posts
    10

    Insert in Database witout dataset ? how ?

    Hi,

    I have a small database in access. I have an application that will generate report (crystal reports) and I have another one (running on another computer etc...) that insert data in the my small database.

    My application have 2 thread that use the method to insert and I don,t want to lose time and resources on filling and updating a table using dataset.

    Is there a way to simply use a sql command to insert this ? (Like in the old time)

    I found this article http://www.codeguru.com/csharp/cshar...cle.php/c4211/

    but System.Data.ADO simply doesn't exist. Was it removed from the framework.net ?

    Thanx to anyone who can help me on this.

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Insert in Database witout dataset ? how ?

    How did you find that article? That article is from 2001. The framework has changed considerable since then. Anyway here is an example using version 2.0 of the .NET Framework.

    Code:
    public void ReadMyData(string connectionString)
    {
        string queryString = "SELECT OrderID, CustomerID FROM Orders";
        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            OleDbCommand command = new OleDbCommand(queryString, connection);
            connection.Open();
            OleDbDataReader reader = command.ExecuteReader();
    
            while (reader.Read())
            {
                Console.WriteLine(reader.GetInt32(0) + ", " + reader.GetString(1));
            }
            // always call Close when done reading.
            reader.Close();
        }
    }
    This example shows how to read from the database. But if you read the documentation for the OleDbCommand you'll see the methods that it has for updating. I assume you have MSDN installed. If you don't you can access it on the msdn website.

  3. #3
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Insert in Database witout dataset ? how ?

    There are different data access classes in the framework but look at the System.Data and System.Data.OleDb since you're connecting to the access database.

  4. #4
    Join Date
    Feb 2008
    Posts
    10

    Re: Insert in Database witout dataset ? how ?

    Thank You,

    I found the article with google, that's why it's so old.

    I will look at these class and probably come out with what I need.

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