Click to See Complete Forum and Search --> : Insert in Database witout dataset ? how ?


JNic
March 8th, 2008, 04:08 PM
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/csharp/cs_data/article.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.

nelo
March 8th, 2008, 04:26 PM
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.


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.

nelo
March 8th, 2008, 04:27 PM
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.

JNic
March 8th, 2008, 04:53 PM
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.