晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
% l3 K; o+ `1 t! I+ ]- P9 Q. U7 {& X! s
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
5 s) N( Z. Y0 `! \0 `' `4 o+ a; V# m
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
) n  G( S( C' S) ahttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
4 `2 O" |6 Y2 Y4 Mhttp://www.itwis.com/html/net/c/20100506/8234.html6 I9 j( k3 X! e: [6 R8 a
0 W$ E1 O1 _' T
程序代码) A1 {# I9 e- V) l/ `5 v* H: r) s
1) public string[] Split(params char[] separator)1 P0 y( ]1 t1 y4 h. x
2) public string[] Split(char[] separator, int count)
3 H. N- u. h! U( j3) public string[] Split(char[] separator, StringSplitOptions options)
( i9 z/ e: |2 T9 a4) public string[] Split(string[] separator, StringSplitOptions options)9 v8 `" c, B* U  p
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
" a* @) z8 E, \0 ^7 I6) public string[] Split(string[] separator, int count, StringSplitOptions options)
+ b  O( |( E6 Q% h6 a4 v5 ?! l8 K8 ]. J* @9 U3 X* C
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
( t% m3 r  D( \, S! f
- t* K# d1 X& ]5 x' v1. public string[] Split(params char[] separator); V7 X/ L  m7 a+ \
- o3 M2 B$ ~$ }" Q' w0 o
程序代码
: J. ]# j% _! n1 Z* Lstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
0 J& S+ j  x' J, Zstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}( q! N& V2 {' H4 E# o7 t  n

0 ^& e1 ?. a7 g' T2. public string[] Split(char[] separator, int count)
% }1 u  C$ q' Q+ I9 \& g' d. _; h2 a) l/ a# K
程序代码
6 G0 Y' U# j* H0 T! ]  E$ G: C# Pstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}/ S3 J4 E* E% f5 E
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
" r; T& ]% ^+ Y, y) O: A  Q  z  A
" Q* r7 s7 ^# f  f5 P; [2 z3. public string[] Split(char[] separator, StringSplitOptions options)9 Y  M1 h8 t$ `+ e( k4 ?" w* C
( R  _0 e, a. w5 ^* Q7 M* x2 k
程序代码
) V" U9 o  r5 T  z7 h) S+ H+ qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素* W# D2 q! Y* R! N
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ w) z- ]( |  W' e5 \
0 Q8 A- Q; A: ^% I! ]5 v
4. public string[] Split(string[] separator, StringSplitOptions options)
, {- T0 s1 J4 }3 {( |: f* X7 f9 a5 E# O4 a( D0 z- M; h
程序代码
: ?; |  y7 w* T  _# M1 _string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
9 b- ~' K& z, Y/ I6 `! B4 ^string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素0 q& |, t+ i/ c- c/ i

! w5 v  i* N3 H) d, O5. public string[] Split(char[] separator, int count, StringSplitOptions options)
' E5 v3 O: j/ }( ~" h; a7 k
4 W: C1 Z! E# n1 C/ G0 D# b: G 程序代码
! ^9 e3 u3 o7 \# @  [+ gstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素- Y3 t7 F* l$ Z' N2 p; I, P
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 c  ^* \- O/ I$ x+ B

: ^& D# p1 M8 x6. public string[] Split(string[] separator, int count, StringSplitOptions options)
" B, z( r) @$ G
( Q, G5 M3 X* g2 V/ Y! ]  o8 \代码# o& ^6 E, V0 }" M. [1 c* u
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素& h9 }" g/ U9 ]5 f0 p0 e% x- N. m
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-5 03:50 , Processed in 6.067616 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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