SQL Data Access Class and Casting DataSets
-
I've put a SQL Data Access class together which returns a DataSet. I wanted it to be generic, therefore wrote a method to return a dataset. I am using typed datasets within my application however and the cast throws an error;
MyDefinedSchemaDataSet myDS = (MyDefinedSchemaDataSet)myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName");
If i use DataAdapter.Fill on a MyDefinedSchemaDataSet.MyDefinedDataTable everything works and there are no errors, however that would throw the idea of a generic method out of the window... what to do!? :confused: -
I've put a SQL Data Access class together which returns a DataSet. I wanted it to be generic, therefore wrote a method to return a dataset. I am using typed datasets within my application however and the cast throws an error;
MyDefinedSchemaDataSet myDS = (MyDefinedSchemaDataSet)myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName");
If i use DataAdapter.Fill on a MyDefinedSchemaDataSet.MyDefinedDataTable everything works and there are no errors, however that would throw the idea of a generic method out of the window... what to do!? :confused:Try this
DataSet utDataset = myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName");
MyDefinedSchemaDataSet myDS = new MyDefinedSchemaDataSet();
myDS.Load(utDataset.Tables[0].CreateDataReader(), LoadOption.OverwriteChanges, myDS.myTableName);
Just change the values where appropriate.
Broken Bokken You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod http://www.brokenbokken.com
-
Try this
DataSet utDataset = myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName");
MyDefinedSchemaDataSet myDS = new MyDefinedSchemaDataSet();
myDS.Load(utDataset.Tables[0].CreateDataReader(), LoadOption.OverwriteChanges, myDS.myTableName);
Just change the values where appropriate.
Broken Bokken You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod http://www.brokenbokken.com
-
works perfectly! thanks thats what i've been looking for!!!! think i'll pass parameters in as an arraylist... although not certain yet...
you should look into using the params keyword instead of an arraylist.
public void MyMethod(params object[] parameters)
{
//do stuff
}When you call it you can pass them in without having to create a list. You can add as many parameters as you want and is great when you need to pass a list as a parameter to a method.
Broken Bokken You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod http://www.brokenbokken.com