晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
) R/ m9 S) w7 H7 @# q6 u
: n) @1 o; o8 r读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码. m: V6 y2 ]( v% @$ Z1 K( m

9 Q. g5 `: p8 V9 B: l对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别' O5 w: p  R5 F1 V1 H/ j# \5 s
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看/ j2 V) K/ a) n) n! {, i! m
http://www.itwis.com/html/net/c/20100506/8234.html  i! |* C; s# @

- U& G) t. ~9 |& E, O& X程序代码
) f) L: a5 \# S+ f' d3 b( R1) public string[] Split(params char[] separator)$ C! J( P2 P+ B8 o  k' m; d: ^6 j
2) public string[] Split(char[] separator, int count): _9 g6 o" H, h
3) public string[] Split(char[] separator, StringSplitOptions options)! Y- V$ o. I1 V  x# k! U
4) public string[] Split(string[] separator, StringSplitOptions options): o- \5 I6 p  u# C  `0 b
5) public string[] Split(char[] separator, int count, StringSplitOptions options)% ]- s3 g: K6 c. E  G
6) public string[] Split(string[] separator, int count, StringSplitOptions options)0 H* w  q8 e- S5 z! s( q( ~
0 O& u# j% P2 H, R- y. G# f' G
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):: H) ~# Z' v* ~$ L; C, @$ K. B
) g5 R# l% c+ S& e) [
1. public string[] Split(params char[] separator)
, l: ]9 J) _! |1 e. o# `1 r) d' }2 A$ ?) b8 k' B) _8 }  z' G
程序代码  b- I$ y  U3 t4 R- A0 F
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
% h' D) m+ C( B' E- W" F% Estring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}+ I0 V/ k9 ?* }3 b
& @  M( ]5 I/ m! `9 G
2. public string[] Split(char[] separator, int count)7 u  G  g( e( x2 X0 r( D. \
# Y/ r* M" q. M. W7 B
程序代码
! [4 ~0 A; D, a5 O$ D7 O7 l$ A7 Rstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
9 m* G* m3 f. p: [: }  a4 Q. bstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}& a( I. N5 f' x8 e& F2 d( g
! U& F& D4 s; o6 Q; r, W9 I1 P
3. public string[] Split(char[] separator, StringSplitOptions options)( A5 h1 ]; P. [& k8 w7 ?& N5 L

+ J/ _# _- w8 m) }) t7 x 程序代码
) Q, x5 ~, U' I) f+ H0 ?( Mstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
% ?! ^# u. u; f) D6 X. wstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素. H3 C- u6 u9 N+ J
- Y+ S) l- V& Z/ w2 U. y2 ~: t+ E
4. public string[] Split(string[] separator, StringSplitOptions options)
8 k4 _* {: u1 _4 O2 O
  c% b1 V4 Q/ ]0 S) z 程序代码$ G2 d' Y- Y' H& i5 j
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素! D5 `+ m  D3 m( d# @
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 g: \* w  h& j" |9 ^. h4 ]3 Y3 g6 {1 o5 Q5 b" G% W
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
6 u, f- Z; f7 [/ L
) I( h' {( P4 D7 Y+ m! @ 程序代码& z4 ^# f- |& v3 G* s0 m
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素" i# W- f! b- ]1 _# U
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 V7 [7 |  N: ~5 P

; q; M& b# N+ f6. public string[] Split(string[] separator, int count, StringSplitOptions options)
2 f. N/ c8 z. a" @1 `8 O1 c: S7 I6 z; b  B9 d9 E& ]4 S
代码
, \; _$ p. W4 S2 u/ l* hstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
" `, H+ D, P% j* l- w3 a' w& i) Qstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-20 11:31 , Processed in 6.068593 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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