Answered by:
Gridvew with AccessDataSource

Question
-
User-72198832 posted
How do I assign database to AccessDataSource control dynamically.
If I load aspx page by mypage.aspx?DB=100 then I want to use 100.mdb as data base
If I load aspx page by mypage.aspx?DB=200 then I want to use 200.mdb as data base
Both databases are identical except for the fact that data is different.
Here's default code - Need to replace Bold Code with equivalent of DataFile = response.querystring("DB") + ".mdb"
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="c:\trims2k\000001000.mdb"
SelectCommand="SELECT * FROM [EquipmentUsage]"></asp:AccessDataSource>
Any help is appreciated.
Lee
Friday, November 5, 2010 4:09 PM
Answers
-
User187056398 posted
If you need VB, there are online converters:
protected void Page_Load(object sender, EventArgs e) { String DBMode = Request.QueryString["DB"] as String; if (DBMode != null) { String FileString = String.Format("c:\trims2k\00000{0}.mdb", DBMode); AccessDataSource1.DataFile = FileString; } }
You can modify the format string as you require.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 5, 2010 4:31 PM
All replies
-
User187056398 posted
If you need VB, there are online converters:
protected void Page_Load(object sender, EventArgs e) { String DBMode = Request.QueryString["DB"] as String; if (DBMode != null) { String FileString = String.Format("c:\trims2k\00000{0}.mdb", DBMode); AccessDataSource1.DataFile = FileString; } }
You can modify the format string as you require.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 5, 2010 4:31 PM -
User-72198832 posted
Steve:
Thanks for getting me going on this.
A couple of new issues you may be able to help with.
1. I have my Access database bound to a Gridview and an able to edit data as long as all columns are set to ReadOnly=False.
If I make one or more columns ReadOnly=True I get the following error on updating:
You tried to assign the Null value to a variable that is not a Variant data type
How do I get past that problem?
2. I have three Numeric columns: Meter, NewMeter, Difference
When editing NewMeter I would like to display value of NewMeter - Meter in Difference Column
Example Meter=1000, NewMeter=1200, Difference is calculated value of 200
How do I trap the edit of NewMeter to make the change to Difference?
Thanks again for your help.
Lee
Saturday, November 6, 2010 5:00 AM -
User187056398 posted
If you have new questions, you need to create a new post (in the correct forum of course!).
Saturday, November 6, 2010 9:41 AM