Changing Data Source at Runtime and Updating DataSet without using SP

Topics: Data Access Application Block
Dec 10, 2007 at 6:56 AM

First of all, I apologize if this not not the right place to put the question about newbie Enterprise library questions. I have couple of questions

1) Changing Data Source at Runtime :
I am using Data Application Block ( 3.1), my database is a Access DB, so I am using Generic database. I have set Data source in enterprise library but I want to change it during runtime say Application.Startup folder. How can change it at runtime.

2) Updating DataSet without using Stored Procedure :
As I am using Access DB I am not using stored procedures. I want to update my data source so that changes ( Insert/Modify/Delete) are reflected to Database. I cannot use "UpdateDataSet" as it requires DbCommands.

Thanks for your time.

Dec 10, 2007 at 8:27 PM
Hi,

Comments inline.


First of all, I apologize if this not not the right place to put the question about newbie Enterprise library questions. I have couple of questions

This is the right place.


1) Changing Data Source at Runtime :
I am using Data Application Block ( 3.1), my database is a Access DB, so I am using Generic database. I have set Data source in enterprise library but I want to change it during runtime say Application.Startup folder. How can change it at runtime.

I don't understand what you mean here. By setting a data source you mean you defined a connection string? How does the Application.Startup folder relates to runtime changes? Please elaborate.


2) Updating DataSet without using Stored Procedure :
As I am using Access DB I am not using stored procedures. I want to update my data source so that changes ( Insert/Modify/Delete) are reflected to Database. I cannot use "UpdateDataSet" as it requires DbCommands.

DbCommands can represent a plain SQL statement. Just use DbCommands of type Text.

Hope this helps,
Fernando
Dec 10, 2007 at 11:57 PM
I answered this in the MSDN forums, but will also post here. Yes, you can do #1, see the solution offered at:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2337911&SiteID=1
Dec 11, 2007 at 1:39 AM
Regarding Updating dataset Here is what I have written. How do update my datasource now.

Database db = DatabaseFactory.CreateDatabase();
DataSet entryDataSet = new DataSet();
DbCommand dbComm = db.GetSqlStringCommand("Select * from tblEntry order by tdate");

// Retrieve the initial data.
db.LoadDataSet(dbComm, entryDataSet, "tblEntry");

// Get the table that will be modified.
DataTable table = entryDataSet.Tables"tblEntry";

// Add a new product to existing DataSet.
// Use the NewRow method to create a DataRow with
// the table's schema.
DataRow newRow = table.NewRow();

// Set values in the columns:
newRow"Item_ID" = mItemTrans.ID;
newRow"Item_Qty" = mItemTrans.Qty;
newRow"Item_Amount" = mItemTrans.Price;
newRow"Item_Total" = mItemTrans.Total_Price;
newRow"tDate" = mItemTrans.Trans_Date;
//newRow"Comments" = mItemTrans.Comments;

// Add the row to the rows collection.
table.Rows.Add(newRow);
table.AcceptChanges();
entryDataSet.AcceptChanges();


Regarding Changing my datasource at runtime.
Let say my datasource at design time was c:\a.mdb and now I want to change it to c:\Db\a.mdb. Usually with enterprise configuration, path of MDB remains hard coded. I wan it to be where my EXE runs.
Dec 12, 2007 at 12:34 PM
can anyone help me out with this one.

Thanks.