sql server - call connectionstring in sqldatasource -
how can call connection string in sqldatasource class instead of writing directly ?
<asp:sqldatasource id="sqldatasource" runat="server" connectionstring="..." selectcommand="sp" selectcommandtype="storedprocedure"> </asp:sqldatasource>
public class cxxx { public string connectionstring() { return "data source=.\sqlexpress;initial catalog=db;integrated security=true;multipleactiveresultsets=true;pooling=false;"; } }
declare object
protected cxxx _myobject;
then, in page_load:
protected void page_load(object sender, eventargs e) { _myobject = new cxxx(); }
then, in default.aspx, can do:
<asp:sqldatasource id="sqldatasource" runat="server" connectionstring="<%= cxxx .connectionstring() %>" selectcommand="sp" selectcommandtype="storedprocedure"> </asp:sqldatasource>
Comments
Post a Comment