Seems this topic causes some confusion, considering the number of posts I’ve seen asking how its done. The documentation doesn’t make it obvious, indeed I don’t think there’s an example in the documentation. Anyway a trawl of the DAAB class reference documentation offers some solutions.
Target environment: MS Enterprise Library June 2005, .NET v1.1, VS.NET 2003
Filling a typed DataSet using can be accomplished in a number of ways, whilst at the same time maintaining provider independence…
1). Filling a Typed DataSet (relinquishes control of connection to DAAB)
public SomeTypedDataSet GetTypedDatasetType1()
{
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper cmd = db.GetSqlStringCommandWrapper(“SELECT * FROM TABLE_NAME”);
SomeTypedDataSet ds = new SomeTypedDataSet();
db.LoadDataSet(cmd, ds, “TABLE_NAME”);
return ds;
}
2). Filling a Typed DataSet (relinquishes control of connection to DAAB)
public SomeTypedDataSet GetTypedDatasetType2()
{
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper cmd = db.GetSqlStringCommandWrapper(“SELECT * FROM TABLE_NAME”);
DataSet uds = db.ExecuteDataSet(cmd);SomeTypedDataSet ds = new SomeTypedDataSet();
uds.Tables[0].TableName = ds.TABLE_NAME.TableName;
ds.Merge(uds);
return ds;
}
3). Filling a Typed DataSet (retaining control of connection, for connection reuse perhaps)
public SomeTypedDataSet GetTypedDatasetType3()
{
SomeTypeDataSet ds = null;
Database db = DatabaseFactory.CreateDatabase();
using( IDbConnection conn = db.GetConnection() )
{
using( DbDataAdapter da = db.GetDataAdapter() )
{
DBCommandWrapper cmd = db.GetSqlStringCommandWrapper(“SELECT * FROM TABLE_NAME”);
cmd.Command.Connection = conn;
((IDbDataAdapter)da).SelectCommand = cmd.Command;conn.Open();
ds = new SomeTypeDataSet();
da.Fill(ds, “TABLE_NAME”);
}
conn.Close();
}
return ds;
}
i am facing dbtype curser problem can you please send me the code
Is it possible to use DAAB with strongly typed DataSets generated by Visual Studio?