Im a newbie to .net and c# so forgive me if im asking a stupid question. Im trying to get up to speed asap, ive figured out how to connect to a database - but i was wondering how do i store the connection in an external file so i can just simply import it into the asp.net page instead of manually writing the connection on each page.
Can this be done? if so how?
If have enclosed my orginal code if that helps.
:::::::::::::: CODE :::::::::::::::::::::::::::::
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
// function to create variables to hold information that we need
void Page_Load(Object sender, EventArgs e)
DataSet DataSet1 = new DataSet();
// strConnect contains database connection 'Microsoft JET.OLEDB' for MS ACCESS, connection string will change upon db used
strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;";
strConnect += @"Data SOurce=D:uniEnterprise Web Applicationsassignmentdbewa.mdb;";
strConnect += @"Persist Security Info=false;";
// the database query
strCommand = "Select * from Type";
// next 3 lines :: take above code and create 2 objects 'Connection' & 'DataSet1' and populate DataSet1 object with data read from the DB
objConnection = new OleDbConnection(strConnect);
objCommand = new OleDbDataAdapter(strCommand, objConnection);
// The last 2 lines tell datagrid(HTML section) to use DataSet1 as its source
Appreciate any help
Thanks in advance
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!