是高手的来吧 !!!

woff 2003-10-18 11:12:53
在Web.config页里
<appSettings>

<add key="conn" value= "server=127.0.0.1;uid=sa;pwd=49513;database=wofe.net" />

</appSettings>

是连接数据库的

我想在页面中控制127.0.0.1、sa、49513、wofe.net的值, 也就是说上述几个值可以根据环境的不同而在页面中随意设置!! 该怎么实现!!!
...全文
31 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyg9108 2003-10-19
  • 打赏
  • 举报
回复
以下为VB.NET代码:

假定Web.Config的路径为 "c:\wwwroot\intepub\Web.Config"
imports MSXML

'读取配置
Private Sub ReadConfig()
Dim objDocument As New DOMDocument
Dim configNode As IXMLDOMElement
objDocument.Load("c:\wwwroot\intepub\Web.Config")
configNode = objDocument.getElementsByTagName("add").item(0)
Dim strServer As String = configNode.getAttribute("value")
Dim struid As String = configNode.getAttribute("uid")
Dim strpwd As String = configNode.getAttribute("pwd")
Dim strDB As String = configNode.getAttribute("database")
End Sub

'写入配置
Private Sub WriteConfig()
Dim objDocument As New DOMDocument
Dim configNode As IXMLDOMElement
objDocument.Load("c:\wwwroot\intepub\Web.Config")
configNode = objDocument.getElementsByTagName("add").item(0)
Dim strServer As String = "127.0.0.1"
Dim struid As String = "testUser"
Dim strpwd As String = "testPwd"
Dim strDB As String = "testDB"
configNode.setAttribute("value",strServer)
configNode.setAttribute("uid",struid)
configNode.setAttribute("pwd",strpwd)
configNode.setAttribute("database",strDB)
objDocument.Save("c:\wwwroot\intepub\Web.Config")
End Sub

兄弟是不是应该多加点分!!!
guoyan19811021 2003-10-19
  • 打赏
  • 举报
回复
放到XML中,还是比较方便的
读取XML中的字段,来去定服务器的设置
ddangerous169 2003-10-19
  • 打赏
  • 举报
回复
可以放在.xml中,可读可写,还方便
woff 2003-10-19
  • 打赏
  • 举报
回复
怎么解决呀 给个办法!
xinxincao 2003-10-18
  • 打赏
  • 举报
回复
不知道怎么通过程序写Webconfig,
读它就是拿来用的,既然你要经常改变连接串,就直接在程序里写,不去读Webconfig不行吗
酋长 2003-10-18
  • 打赏
  • 举报
回复
reade web.config,then update value dynamic;
loulanlouzhu 2003-10-18
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2191/2191025.xml?temp=.5962641
513 2003-10-18
  • 打赏
  • 举报
回复
建议不要方在WebConfig中。
可以建立一个系统数据库,将ConnectionString存在其中。
若一定要这样,也可实现,查找关于WebCofig的贴子吧!

62,025

社区成员

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

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

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

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