数据库连接的问题

keeploveswawa 2003-08-25 02:28:14
我在web.config里加了 <appSettings>...</appSettings>

在.aspx的页面里应该如何调用呢? 希望各位高手给出详细源代码

谢谢
...全文
16 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
johnlenfu 2003-08-26
  • 打赏
  • 举报
回复
webconfig:
--------------------------------------------
<appSettings>
<add key="ConnString" value="server=xxx;database=xxx;uid=xxx;pwd=xxx"/>
</appSettings>


.aspx
-----------------------------------------------
Dim strConn As String = ConfigurationSettings.AppSettings("ConnString")

...
...
...
Dim conn As SqlConnection = New SqlConnection(strConn)
..
..
pingan99 2003-08-26
  • 打赏
  • 举报
回复

dim my_str as string = configurationsettings.appsettings("you_keys")
acewang 2003-08-25
  • 打赏
  • 举报
回复
private void Page_Load(object sender, System.EventArgs e)
{
strconn="server =(localhost);uid =sa;PWD=111111;DataBase=StopFire";
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string strSQL = "select Area,Author,BaseInfo from BaseInfo Where ID='" + Request.QueryString["ID"] + "'";
SqlCommand cm= new SqlCommand(strSQL,cn);
//Response.Write(strSQL);
//Response.End();
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{ Label1.Text = dr.GetString(0);
Label2.Text = dr.GetString(1);
Label3.Text = dr.GetString(2);
}

dr.Close();
cn.Close();
}
standy 2003-08-25
  • 打赏
  • 举报
回复
怪你问的问题没有针对性了:)

keeploveswawa 2003-08-25
  • 打赏
  • 举报
回复
说实话,我没看懂各位的,不过谢谢了~~

不知道哪位能继续啊,我想要的的是,比如,我点一个按钮,就要和数据库连接了

然后把数据库里的内容显示到页面上来,就是这个按钮里的 连接数据库 的代码怎么写

我用的是VB.NET谢谢~~, 分不够的,我再送!!!
wacle 2003-08-25
  • 打赏
  • 举报
回复
in web.config:
<appSettings>
<add key="CNString" value="server=server;uid=sa;pwd=;database=DB" />
</appSettings>

in aspx.cs:
string sets=ConfigurationSettings.AppSettings["CNString"].ToString();
salonwang 2003-08-25
  • 打赏
  • 举报
回复
<appSettings>
<add key="cnnstring" value="server=;database=;user id=;password=;trusted_connection=false" />
</appSettings>
using System.Configuration;
string connstring = ConfigurationSettings.AppSettings["cnnstring"];
lwgj 2003-08-25
  • 打赏
  • 举报
回复
Dim nowdsn As String = ConfigurationSettings.AppSettings("dsn")
Dim MyConnection As SqlConnection = New SqlConnection(nowdsn)
vivaldi16 2003-08-25
  • 打赏
  • 举报
回复
ms-help://MS.VSCC/MS.MSDNQTR.2002OCT.1033/cpguide/html/cpgrfaccessingappsettingssection.htm
lihonggen0 2003-08-25
  • 打赏
  • 举报
回复
访问 appSettings 节 [Visual Basic]请参见
配置节设置 | 配置节架构
语言
C#

Visual Basic

全部显示


.NET 框架提供名为 appSettings 的预定义配置节。下面的示例说明,appSettings 节在计算机配置文件 (Machine.config) 中出现时对它的声明。

<configuration>
<!-- Configuration section declarations. -->
<configSections>
<!-- You do not need to declare the appSettings section. Machine.config ships with a declaration for this section. -->
<section name="appSettings"
type="System.Web.Configuration.NameValueSectionHandler"/>
</configSections>
</configuration>
下面的示例说明如何在使用内置 appSettings 节的配置文件中使用应用程序设置。

<configuration>
<!-- The following code uses the predefined appSettings section. -->
<appSettings>
<add key="Application Name" value="MyApplication" />
</appSettings>
</configuration>
ConfigurationSettings.AppSettings 是特殊属性,它提供指向配置文件的 <appSettings> 节中定义的应用程序设置的快捷方式。下面的示例说明如何检索在前一个配置文件示例中定义的应用程序名。

[Visual Basic]
Public Sub ReadMyAppSettings()
Dim appName As String

appName = ConfigurationSettings.AppSettings("Application Name")

Console.WriteLine()
Console.WriteLine("Reading AppSettings")
Console.WriteLine("Application Name: " & appName)
End Sub
[C#]
public void ReadMyAppSettings()
{
string appName = ConfigurationSettings.AppSettings["Application Name"];

Console.WriteLine();
Console.WriteLine("Reading AppSettings");
Console.WriteLine("Application Name: " + appName);
}
请参见
lihonggen0 2003-08-25
  • 打赏
  • 举报
回复
Imports System.Configuration


Public Shared connString As String = ConfigurationSettings.AppSettings("connString")

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧