晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件5 n3 H7 F+ }3 ~; N7 {

5 Q" J6 N3 |. O, j& s0 d读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
" A5 F) s9 Y( C5 H2 E" ]
$ K5 l+ r) _/ ?" X. j$ ?" t对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
1 W3 Z3 S$ f6 t2 Mhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看6 J# q% h3 b% B+ R4 I/ U
http://www.itwis.com/html/net/c/20100506/8234.html9 P$ w) [% V% J6 f1 E' p
3 }( U9 S8 M3 F; j$ v3 W  ]+ ?
程序代码  c- o5 {; J. X/ {/ }, G
1) public string[] Split(params char[] separator)! J+ y5 p0 @( `
2) public string[] Split(char[] separator, int count)$ P: t8 @+ Y) }
3) public string[] Split(char[] separator, StringSplitOptions options): S" @* e3 n0 T$ b9 `- u
4) public string[] Split(string[] separator, StringSplitOptions options)
5 b8 @: R) r, V4 r# e+ ?# V6 |5) public string[] Split(char[] separator, int count, StringSplitOptions options)
& L# g" U* [' T7 c) G6) public string[] Split(string[] separator, int count, StringSplitOptions options)
  ]5 g1 q, _9 L) z6 Y; i& V$ b; {: v5 d* I
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):2 `4 c/ p$ Y8 N9 q# c" g4 \

2 v- Y* \" o* N% i5 l) r1. public string[] Split(params char[] separator)1 E$ l2 U2 }! O8 d: @! e0 v6 t. k
3 c! k( E; }' r' {0 {0 V& p# m
程序代码
3 C1 r7 w2 ]" w$ L( p+ f7 Vstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}- @( o9 s* x+ S+ `% s7 M" s! o
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}$ T2 n5 k! N% C9 A1 n9 e
4 A7 J+ B4 Z; [7 N  C$ A
2. public string[] Split(char[] separator, int count)
' P& u9 W& m0 Z% G1 A% @! E# j# n$ W+ q/ e, u+ J8 Q' j
程序代码& r+ j2 H9 V7 _) Z+ q
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}  z+ W7 U3 m8 j2 Q( R
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}, c' E4 t3 r% p6 u; ?4 U
2 p2 z  E" p. a  ?
3. public string[] Split(char[] separator, StringSplitOptions options)( ^- i# x3 J) Z( M7 L
2 d. A: ?8 k0 w& B
程序代码' J- c, w3 O9 `) _
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
8 Q* V) `; ~' ]: Sstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" C2 t0 ~0 U( D2 Z

, F: }! X( M& W. t- a1 H: v4. public string[] Split(string[] separator, StringSplitOptions options)1 p; F, i8 a4 D' q  |5 n( H/ L
9 f0 Q7 J7 H& ]! k
程序代码% Y# b- _8 K) N* f# a8 c
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# I. o$ A0 |. P
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ h  k- c3 G% x# b" Y2 _1 T
& D. U$ r4 ^6 h: Y1 n
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
7 y/ B( d' p8 l: {2 l2 y
+ I- D; f! l; c% \ 程序代码. y  u6 I6 _% r0 W( R; {7 L
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素+ z/ l7 B  z, C$ Q+ g( T$ a) O: Y/ }
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 ~7 f! _2 Z( o! u7 z) z

! D, Y% z9 V5 f; Z) t4 N& W+ d4 D6. public string[] Split(string[] separator, int count, StringSplitOptions options); A: q6 n. _( Z7 j' V2 `% u6 d" y

, E0 T' D7 Z: K0 ^& ~+ l代码
$ ^; D- n' ?& m2 h* ystring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 |4 v- r! S5 o7 o; Zstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-29 09:04 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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