晨鸟科技

 找回密码
 注册
搜索
查看: 13552|回复: 3
打印 上一主题 下一主题

升级程序开发——读Web.config、执行Sql脚本

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
0 }; {8 O: [1 T6 L: Q6 l  ?$ ?  }! G3 y2 D
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
) K' O3 ^3 m. N* N0 L4 w6 A; s% z6 f8 h/ w& s' B4 W' N  ]
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别2 ]3 ~3 _/ l, i6 ~6 L
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看$ T' d7 a' y' ?8 h( f
http://www.itwis.com/html/net/c/20100506/8234.html
5 M' B7 C( G: ]# }1 G
; G+ r. U! S3 g/ P* [程序代码( ~5 \( Z( m7 G; K/ C: p" i
1) public string[] Split(params char[] separator)" ]5 T/ a2 y! {  N% a
2) public string[] Split(char[] separator, int count)
3 ?( H, O; k7 Y3) public string[] Split(char[] separator, StringSplitOptions options)* N) k, D( M- Q) }; o) X( t
4) public string[] Split(string[] separator, StringSplitOptions options)
1 D9 u& B) o* O" s+ V5) public string[] Split(char[] separator, int count, StringSplitOptions options)
) i. O2 _8 p, l6) public string[] Split(string[] separator, int count, StringSplitOptions options)! r3 r, ]4 P5 M! k* h8 \2 ?1 ~' B

. |4 o# ^- l% T  [) ^下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
, v: Z9 v( K3 T; j: f+ [' Q6 ~3 o" \& n
1. public string[] Split(params char[] separator)& K6 B( u! v6 s) z- T3 q, S' n
( [. w/ T5 i  Z! P9 ~) E% s
程序代码6 x5 g# e! M4 D9 y" M2 H
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
* }4 W" S. z+ ystring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
6 }, W' d7 e! W( F1 Z& m% r- H8 d2 E, R) j7 i6 Q: f
2. public string[] Split(char[] separator, int count); K5 F7 e5 [; s8 {3 I
; {3 D! N# P8 L- w# m
程序代码" T' j4 t8 }! n" ?* J5 A' ]  T
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
% I0 g2 `/ S5 \- e2 n9 fstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
  a% k; E. }- O8 M1 B! Y  }4 [7 K" f" g
3. public string[] Split(char[] separator, StringSplitOptions options)
; g7 o) n9 X8 V  ]5 c$ I7 p' Y! a  w- R3 g' q
程序代码& p% w3 d' `0 _$ l) k) m2 U2 W
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
. B; ^# R# i' s! T8 W% ^) r$ s% y% ^/ Astring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素0 {9 W( p, t4 x' T, c8 \# K

6 F' n+ l1 x* e" d4. public string[] Split(string[] separator, StringSplitOptions options). ^3 Z: |3 q7 v* ?- F
3 o; w" b& d4 E
程序代码9 U  d' ~7 \/ C) g
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素  e4 n. q" c& \2 _; I
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素! v% T$ F' f1 `3 p+ H

- q7 L$ A  h8 |& Q2 ^7 ]5. public string[] Split(char[] separator, int count, StringSplitOptions options)
) r/ F( @7 `) ^# A# ?3 s1 m# x- ]( \
程序代码9 a" M& z' c/ ^4 ~& B  L
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
% }" E1 v* g) zstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素+ K+ m5 A' a' J. f: ^$ R3 E
; i* ^& @+ @* F) Q% I
6. public string[] Split(string[] separator, int count, StringSplitOptions options). _" J" t' s) @2 o

1 ?1 h1 R6 z8 O: o1 ~' {' o  m代码9 C0 Q# z- M$ N  y
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素1 O% l! X. N  l  y. \, |! f& e
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|晨鸟科技 ( 沪ICP备09012675号 )

GMT+8, 2025-12-29 22:10 , Processed in 6.070545 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表