Thursday, March 22, 2012

OleDbDataReader to OleDbDataSet

I'm trying to convert this component from OleDbDataReader to OleDbDataSet.

All the examples I saw uses the .Fill, I can use it in the components .. true ?

Hope you can help me.


public OleDbDataReader GetProductsDetails (int intKatID) {

// Build SQL
string sSQL = "";

sSQL = "Select *";
sSQL += " from Products";
sSQL += " Where CategoryID = ("+ intKatID +") ";
sSQL += " Order by ModelName";

OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
OleDbCommand myCommand = new OleDbCommand("sSQL", myConnection);

myCommand.Connection = myConnection;
myCommand.CommandText = sSQL;

myConnection.Open();
OleDbDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

return result;

}

Something like this should work:

<code>
public Dataset GetProductsDetails (int intKatID) {

// Build SQL

string sSQL = "";

sSQL = "Select *";

sSQL += " from Products";

sSQL += " Where CategoryID = ("+ intKatID +") ";

sSQL += " Order by ModelName";

OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

OleDbCommand myCommand = new OleDbCommand("sSQL", myConnection);

myCommand.Connection = myConnection;

myCommand.CommandText = sSQL;

myConnection.Open();

Dataset myDataset = new Dataset()
OleDbDataAdapter myAdapter = new OleDbDataAdapter(myCommand)

myAdapter.Fill(myDataset)

return myDataset;

}
</code<

0 comments:

Post a Comment