using System.Data; using DbAgentObj; // create a new instance of DbAgentObj DbAgentObj db = new DbAgentObj(); // execute a SELECT query string query = "SELECT * FROM customers"; DataSet ds = db.FillDataSet(query); // display the query result foreach (DataRow row in ds.Tables[0].Rows) { Console.WriteLine(row["CustomerID"] + " " + row["CustomerName"]); }
using System.Data; using DbAgentObj; // create a new instance of DbAgentObj DbAgentObj db = new DbAgentObj(); // execute a parameterized query string query = "SELECT * FROM orders WHERE OrderDate > @date"; DbParameter[] parameters = new DbParameter[] { db.CreateParameter("date", DbType.Date, new DateTime(2022, 1, 1)) }; DataSet ds = db.FillDataSet(query, parameters); // display the query result foreach (DataRow row in ds.Tables[0].Rows) { Console.WriteLine(row["OrderID"] + " " + row["OrderDate"]); }This example shows how to use FillDataSet to execute a parameterized query with a parameterized value. Both examples use the DbAgentObj package library to connect to the database and retrieve data. The FillDataSet method is called with the SQL query and optional parameters to execute the query and fill a DataSet object with the result. The DataSet object can then be iterated to display the result.