在ASP SqlDataSource中定义ConnectionString [英] Defining ConnectionString in asp SqlDataSource
本文介绍了在ASP SqlDataSource中定义ConnectionString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我在 web.comfig
中的< appSettings>
下定义的数据库连接:
I have my database connectivity which I define under <appSettings>
in web.comfig
:
<appSettings>
<add key="ConnStr"
value="Data Source=dsk-159\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"/>
</appSettings>
但是问题是我无法像这样尝试从我的aspx页面访问它
But the problem is that I am unable to access it from my aspx page as I am trying like this
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:goldsConnectionString %>"
SelectCommand="SELECT distinct TechnologyId , [TechnologyName], [ChildId] FROM [TreeTable] where childid is null AND technologyid in(@hid1)">
<SelectParameters>
<asp:ControlParameter ControlID="hid1" Name="hid1" DefaultValue="23" />
</SelectParameters>
代替< connectionStrings>
我想在< appSettings>
Plesae告诉正确的语法.
Plesae tell the correct syntax.
推荐答案
您的web.config应该如下所示:
Your web.config should be like below:
<appSettings>
<add key="ConnStr" value="Server=yourservername;Database=yourdatabasename;UID=yourusername;Password=youruserpassword"/>
</appSettings>
您的.aspx文件应如下所示:
And your .aspx file should like following:
<asp:GridView ID="grd" runat="server" DataSourceID="SqlDataSource2">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ appSettings:ConnStr %>" SelectCommand="SELECT * FROM ticketmaster"></asp:SqlDataSource>
这篇关于在ASP SqlDataSource中定义ConnectionString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文