Change gridview datasource to connection sting in web.config. ASP.Net 2.0, VS2005, VB.Net, Access Database
Posted on 2007-11-24
I guess this is so basic no one shows how to do it...
The host I use wants me to use a direct path to the database. When I drag a gridview onto the page, it asks for a datasource. I enter the information and everything works fine.
However, I've read that you shouldn't have the physical path in the aspx file, it should be in the webconfig file. So, I need to know how to convert this to the webconfig file:
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="C:\myDirectory\database\events.mdb"
DeleteCommand="DELETE FROM [events] WHERE [eventID] = ?" InsertCommand="INSERT INTO [events] ([eventID], [eventName], [eventDate], [eventTime], [eventAddress], [eventCity], [eventState], [eventPhone], [eventDescription]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
SelectCommand="SELECT * FROM [events] ORDER BY [eventID] DESC" UpdateCommand="UPDATE [events] SET [eventName] = ?, [eventDate] = ?, [eventTime] = ?, [eventAddress] = ?, [eventCity] = ?, [eventState] = ?, [eventPhone] = ?, [eventDescription] = ? WHERE [eventID] = ?">