晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
. m2 k4 c* P: \" r9 x/ [5 G8 B0 T: J3 _0 [( a) c$ d( O
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
+ k* V2 b' G) ?4 b- m5 ^4 Y+ N- I1 B' h" ~; ?0 O9 P3 @
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别/ i" J) v3 e8 H1 u' Y, \$ E( c
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看! x) S/ J$ F$ v
http://www.itwis.com/html/net/c/20100506/8234.html
0 Z9 g6 ?- s+ _0 ^1 r6 O" r5 w0 |3 I/ p  F8 v; X( i
程序代码6 V9 i  W  ~- ~! S# j% H5 E1 L
1) public string[] Split(params char[] separator)
7 v, f, ~* U* T, V6 q; r2) public string[] Split(char[] separator, int count)8 J, T( L7 G; h7 H8 v" ~' l
3) public string[] Split(char[] separator, StringSplitOptions options)4 m% I( o1 O, R- L/ w% Y7 t
4) public string[] Split(string[] separator, StringSplitOptions options)! f5 x6 I0 p8 M
5) public string[] Split(char[] separator, int count, StringSplitOptions options)8 }& B# T9 z1 m9 [3 v/ \3 v$ z
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
4 @& `" m# U1 N9 s$ U5 I% T& S
  M# Y( t* O9 A5 o% b+ ~下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
/ l6 b6 l% P2 r/ ^, X' y6 a! x8 i
; z- E) P' `4 V6 |+ p( g2 Y1. public string[] Split(params char[] separator). R) S3 r' e$ |) n
6 H3 Q9 d* s1 H, J
程序代码
  ]: @1 g9 `5 E5 ]  Jstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
; t) W) K& r' i5 }string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}. ?, m4 m" M  z+ S* L  n0 b

8 O! k+ T  x' T. w% r1 t( f2. public string[] Split(char[] separator, int count)$ u2 h+ z) z! h+ D
" a1 C+ o- K4 C0 A- D; E; a8 e4 T
程序代码
* a  }# q8 v# p# c( fstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}# s1 \- K7 {* X: {5 S! I3 o& {1 W0 h
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}- V5 F) R1 {- `! c

$ n. }5 ?3 A! U; [0 P% d- V3. public string[] Split(char[] separator, StringSplitOptions options)
$ L0 W# c' b# R5 X
3 ^! ~) L; X8 C7 T$ L 程序代码
, F. y/ U- K: t6 L% b) hstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素9 `0 e4 q+ w- O, E: u/ R
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素' d& S* s3 @  D% [' b
6 u& H. Z  C4 F' B5 R5 _7 f
4. public string[] Split(string[] separator, StringSplitOptions options)8 X2 S1 \6 p% F' A2 w3 Q2 C7 s6 F

6 ^9 _' |, ~) X) r+ j 程序代码; u5 {% i+ }9 [0 s- X7 b9 j
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
# ]" Q' Q" W1 }% l. m& gstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* b( l: x- T# v, s- }9 p% g( s7 M3 s! P. S; ?! Y4 M! P
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
; c- J1 L6 m( o  `3 n
3 {: D( ~5 \& A4 r0 f# D 程序代码
( k& b7 e9 P. M' H$ R) Istring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( A4 L4 r4 i& I6 F- O; N6 I' o: D! d
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素; x; K) H* P5 {6 V8 N

% g8 D. ]2 s+ [* r! W9 ?  V6. public string[] Split(string[] separator, int count, StringSplitOptions options)+ I( [. ~' _6 U- O. m

1 B( }! J9 j( `' C; M代码) P; ^9 v- e  c, v
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素  O$ i. \$ o. R" u. {4 A) q
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-4 06:30 , Processed in 6.073830 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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