晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件; _+ p# d- n. ]5 ?+ F) T0 i+ ]6 s
' M& @3 B% c  I0 B& D" U
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
0 p" a# Z8 h2 g8 Z) P
8 k. E0 p  E* {" ~7 m对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
. x4 X1 D/ M! S4 `http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
  S1 W0 @8 B$ h% d) Jhttp://www.itwis.com/html/net/c/20100506/8234.html3 Z3 }9 c, U' {
0 z9 k, D$ \& f. z
程序代码# `6 a" x+ C' |4 k
1) public string[] Split(params char[] separator)$ {% \: ^8 ]/ a: i  q( k
2) public string[] Split(char[] separator, int count)
9 p- W0 n: J4 K+ `3) public string[] Split(char[] separator, StringSplitOptions options)
6 B5 p8 |# i* K4) public string[] Split(string[] separator, StringSplitOptions options)
. {; _# J& \0 c# m, i  j) z$ |0 i5) public string[] Split(char[] separator, int count, StringSplitOptions options)
7 e( `! b2 i8 F1 d. w- q% [6) public string[] Split(string[] separator, int count, StringSplitOptions options)
3 x5 k+ }  Z4 J' r, x. [; o8 P
. E5 M7 z! E0 |下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):! L7 T, c5 p; b0 f* g
: _( z- V* R1 Q) c: N% r
1. public string[] Split(params char[] separator): b8 d" o7 D- t" @- o

1 w/ S2 X+ j" P  x  Q 程序代码
! S+ c8 j" Q8 |6 Gstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
  U  h) A$ w: P! S* _* C% Nstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
, m: |$ i3 u- Z+ k3 M2 m
: [3 A* s% I; F$ W# n4 M2. public string[] Split(char[] separator, int count)# T; o# ?* A4 M

6 o% s" `& p- e, u4 f' _% j 程序代码( m5 c; p; g0 f4 \- E4 C- X5 T- A! s
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
; c1 _1 g. W1 W% jstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}1 v& s% n' F$ B$ g3 d' D8 H  }( t
. X$ i4 v( k  q& _; G% S
3. public string[] Split(char[] separator, StringSplitOptions options). q: j/ U3 I9 ]( r9 ^: F+ f
' N$ X5 c4 t% C6 X* i# H" t1 Q4 Y
程序代码
  [$ h; T9 u2 ~string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
* }" `4 G: @: |4 ]; E. [) P& v' O% ^( astring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
8 |' s: y9 X8 p& E2 H( ~) z0 [
4. public string[] Split(string[] separator, StringSplitOptions options)
; b; D/ g, A# r- i8 V
0 N: a* d+ J% [0 q 程序代码
% D2 h: d9 U+ x. V, M% A. Nstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
2 u& s( n- I. R* U3 q3 M1 r7 xstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
; u7 k( s( T" ^5 ~
- P: K( `. p7 v/ i/ y5 X3 W5. public string[] Split(char[] separator, int count, StringSplitOptions options)
* z  F( Y, H* c% G0 D- f/ n3 _( }
& @( a! y7 ~! K, Z! @5 w" @ 程序代码
% j" I" j7 l5 M; gstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
/ N" r- M! B; U$ [5 x, zstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% s  {# _; b7 e: y* F7 ]# i6 S
  y# E% F; g. k9 ^3 h) M9 U6. public string[] Split(string[] separator, int count, StringSplitOptions options)) s/ z5 c: h' [: @0 Y- t7 ^& U

, c3 Y; {7 m& T  |代码" @% }" n& `" k9 s* ?  b! R5 n
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素0 E" ^; D/ X/ R4 y
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-28 03:17 , Processed in 6.068948 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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