晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
0 x% r6 N" f6 i  G; p. p/ Z
* `# i" ^, ~7 [% Q* }- v7 k: j读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码5 u+ C! L" v3 O. @

! z# E- r0 r+ ]对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别: X5 j& }$ ~2 Y. k& s
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看- c0 I4 i. F9 N4 q0 G
http://www.itwis.com/html/net/c/20100506/8234.html; x# a4 u  b" z: `3 R

$ u3 K- _" M' r' A. s% O程序代码1 v9 m% a$ k; H. g* \' D1 t# N, S
1) public string[] Split(params char[] separator)" A. y5 M# z5 K1 ~) {' A% E
2) public string[] Split(char[] separator, int count)
- S2 t$ z9 q/ R1 \$ U3) public string[] Split(char[] separator, StringSplitOptions options)
/ M! b7 ~! y2 m5 P- f/ y6 Z4) public string[] Split(string[] separator, StringSplitOptions options)
& R8 A9 z4 I" l% L5) public string[] Split(char[] separator, int count, StringSplitOptions options)
$ q$ z) e$ f- e! }) x2 I4 L! Y, s6) public string[] Split(string[] separator, int count, StringSplitOptions options)
" [  _9 J& Y7 x1 H3 E( o% p9 i2 P) i" O% v3 A( j
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
+ v1 A5 g% i, f- _4 |5 w& b/ \4 D7 E
1. public string[] Split(params char[] separator)
! O7 p( h2 C& T6 t: V+ b. P6 H7 P
0 G2 m9 }# e: ]8 ?7 w- _  Z! H 程序代码; V- R* l. O3 Y% K0 w
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
1 V- S; i/ F+ zstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}; r- y% n& C4 b7 g% ^7 j2 M
; X  Z2 |" m; k
2. public string[] Split(char[] separator, int count)- b' F- H, |% c
$ f; ]3 c* q: v+ ]$ n2 v" I& W
程序代码+ `+ N- U" F! i; t; e
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}8 I2 L5 ]2 T! N2 Y8 P
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}- p# o4 E( k4 L- j4 v
# _1 |! v9 g# X) {- S7 C
3. public string[] Split(char[] separator, StringSplitOptions options)
- [4 x6 h6 J2 C' G5 p( y3 n' X& U, Z) T- j4 R  i
程序代码
. i9 M3 O0 A7 Kstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
; t: y  s) [: j$ \5 k" c4 _string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* f! x# v* J% R" t4 x' q3 o( ]* Y: e- w1 n
4. public string[] Split(string[] separator, StringSplitOptions options)' r+ {0 w/ q7 F0 ]4 G; h

- g+ _' v2 ?* s1 K9 N5 D/ k 程序代码% j1 N1 [8 f$ I% N/ I
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
% s5 C& ]4 o  G+ c. hstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
2 ~1 ?: \- H2 J* J$ U# e: ^* v0 m
) D* E# g. w, o3 z# ^5. public string[] Split(char[] separator, int count, StringSplitOptions options)% x$ K( D6 C5 r/ L& V3 X
0 F5 S' h' ]/ m) j
程序代码1 T7 }; H+ \  K& @0 a
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
1 p: a6 N- _( P) i0 W- R# Lstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
2 V1 W6 Q/ T4 F1 o( g8 C  n- {, O6 A# ^5 j! i$ n0 s
6. public string[] Split(string[] separator, int count, StringSplitOptions options)6 q% y0 l$ P. d

9 O0 q- N0 z9 E- |' f5 t& L4 `代码6 O7 \/ \/ |7 n
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 [& `8 @! s/ r+ u. Hstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-10 09:06 , Processed in 6.081288 second(s), 15 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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