晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
( J7 M6 f* v0 J: |3 O( j# d0 ^2 K
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码9 {. w5 t: i$ X, }5 X) D  L; @

4 u. F( P; a9 q: |0 A% b0 `# q  T% J对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别9 O! e6 B* |8 C( H' L3 F
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
" ~: P. J9 q, u* `http://www.itwis.com/html/net/c/20100506/8234.html8 X0 I3 }: m7 Q( T! ^. \4 W  y( c
  H) n( Q& @  A+ Q
程序代码
$ z3 Y+ `0 j- |: @4 O& y1) public string[] Split(params char[] separator)) P5 z" I+ `! @( t: h) X
2) public string[] Split(char[] separator, int count)8 D% Z% d! B9 K2 v8 H" T/ _7 {
3) public string[] Split(char[] separator, StringSplitOptions options)
. t, P4 K" m: C4 z1 J' j7 ?$ r3 H4) public string[] Split(string[] separator, StringSplitOptions options)2 q. t+ Y& j5 h% X/ q  O# y: N
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
, e) i, H+ [2 L* a/ h6) public string[] Split(string[] separator, int count, StringSplitOptions options)( M- ^% F" T& \5 U

. B5 d7 {0 v4 ~8 B) z; ^下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* R) s. P- s' O: F2 L* h# r

% c! }0 q/ k7 [6 ^/ \0 Z, o1. public string[] Split(params char[] separator)
; P! ]  _  P  R4 Q, R% [2 Z" d4 z
. v& ^7 y# y" k- G1 |+ @3 O 程序代码
2 a$ \5 D+ c" |5 Tstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 d! }: z/ @! {4 q, f: R. l
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}% j' P7 d8 Q7 F6 `

: h* u  Q* F" g$ @2. public string[] Split(char[] separator, int count)
8 N5 ]+ a7 r  G" r* m
4 [& L8 R4 [0 A1 u! k) C 程序代码7 ], Q0 A' T+ R5 G5 |* N. U- r
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
  [* b/ V$ m7 n4 S( N& gstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}1 ?1 y7 S3 o+ _. }, b8 e6 a
8 v9 j$ H& w$ A! M* z* e6 k
3. public string[] Split(char[] separator, StringSplitOptions options). T# k/ g) M0 V  D/ P% s5 D

+ D+ {: ^, @; g) ]; w. d 程序代码
3 P: n0 U& j0 pstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
; [1 r8 B: R7 V3 o* a& x, j9 i% l4 Gstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 P+ {% P# E0 R9 T
- a9 P4 I- h1 J5 ?; W: A8 I
4. public string[] Split(string[] separator, StringSplitOptions options)
( i3 r/ z* o! @8 a$ S7 k7 [! L* R4 R) g3 h' N. c0 J" K0 o
程序代码
) Y5 x6 o: N8 Z% {$ N( dstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
% ]; m' `0 {; Z. |string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, Z) p! V3 s7 h+ [5 q8 G

0 l( d* X/ k& E: _$ o2 u/ B0 U5. public string[] Split(char[] separator, int count, StringSplitOptions options)4 y# ^" t( x6 _

+ k4 d& Q; m9 ?) r8 n 程序代码
9 ~, Z" r; n5 w3 e! l7 jstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素, h9 Y7 ^  ^  g6 P$ y; R
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( Y1 m% D4 {1 G9 n' P9 R2 ?' s5 g  H- H/ @
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
# d% e- ^! y8 E
( n- |# Y- C: A. h9 V6 R; s# y$ o代码, A, \* `  X: s
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 |' Y5 ]6 p8 m9 t, m" Cstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-31 07:18 , Processed in 6.065042 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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