晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
' O" q- `$ e7 K/ w- v& b  |( ]3 B7 \" v5 n
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
; D: V/ p7 H/ P* o: J4 c. O
5 {7 p! R& z" w( w9 _对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别" Y* y$ i7 y# Z$ v0 I
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看* W' j$ G, s7 ^* R  J' b8 i
http://www.itwis.com/html/net/c/20100506/8234.html
. |  N9 K$ s+ i, `' Z
3 c5 l! a& S7 M! _7 N程序代码
7 n9 ^9 r% @! w. ^1) public string[] Split(params char[] separator)
0 c- c* Y  s% x8 J, i- m2 p$ `; Q2) public string[] Split(char[] separator, int count)/ X% t6 Z* Q6 d, A6 g
3) public string[] Split(char[] separator, StringSplitOptions options)( C* L# N5 @0 y) d
4) public string[] Split(string[] separator, StringSplitOptions options)* ?: Q1 F- s6 O4 ]; N* X) f: L
5) public string[] Split(char[] separator, int count, StringSplitOptions options)8 p1 X+ P* W' \5 _% b
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
2 i2 e- r4 k! \/ s( W" V' c: I1 }8 Y% h2 z/ Y3 E2 k& S$ G7 C0 K( E& K' `
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):6 P  t; e8 A4 k3 |

1 R# C5 O; W% V$ d' R2 v1. public string[] Split(params char[] separator)1 L* [1 h. g0 {, {$ e/ }7 x$ U

8 U9 b: _7 m5 r& j 程序代码
0 ~( t# Z( W& D" Y" |5 B% zstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}, y" e6 p9 _6 `$ W/ L
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}( A, V1 A! M5 I/ P$ L

& u$ Y" D1 I) b+ f2. public string[] Split(char[] separator, int count)
9 e( u4 J7 ?) ]9 J
5 j8 K! |0 o1 q; X/ p. B% c1 n 程序代码
  f0 m4 V; t+ }! W% S( Istring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
; L- Q' _" N8 E) ?' T) }: kstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}. A. \$ e4 \. Q3 ?7 F
. J* |( [$ e2 B8 d) z9 ^: T
3. public string[] Split(char[] separator, StringSplitOptions options)  E" }# j. _0 }) q7 W# P

( ^# ~* ]2 g3 g7 u- U$ B# j 程序代码7 w4 E" A& u2 ]; T4 \
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素* e& W/ V: U* H. c8 A+ O
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( W& N& H4 h$ ~; x0 E+ `- `! C3 s8 `- Z2 a, ^7 ~' M+ K
4. public string[] Split(string[] separator, StringSplitOptions options)3 v2 P( p. M9 S4 n/ M1 Y  ?! N. I5 B
. e6 F7 G% X' h! h4 X
程序代码1 r! G# {: P2 Q9 a; E; c1 u/ C' I
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# {) b. M8 V( n
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' y7 }1 ]8 D* O$ B, c
1 f' L2 `2 b: p! y% R1 L% H- h5. public string[] Split(char[] separator, int count, StringSplitOptions options)
( \( R5 V, G* V5 ]- g& g
) q0 f5 c' w1 |# I 程序代码! ]) ]  b/ B! T* o0 ]4 R
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# |6 N! B9 G3 {) \string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ n3 \$ Q9 N2 w0 [- v1 ?; R
$ V- P: F  _7 L& j0 O6. public string[] Split(string[] separator, int count, StringSplitOptions options)$ G4 C& g) e* \' j- U' V

( p8 M/ S4 A, U9 X4 L7 e& D代码& g# N# K$ Q, q- I1 c
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 R  ?7 G' E! Xstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-1 13:33 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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