晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
0 n8 c6 V7 {3 U/ r& i: a$ J- D$ T
; a4 R9 @( a7 D1 @9 \读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
8 [# n" \! B$ Y/ q. }1 _& N! k0 Y
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别; j% I8 C4 U. l, c) j
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看: u8 B: f3 t+ V* K
http://www.itwis.com/html/net/c/20100506/8234.html7 @6 R8 `# m4 R% B
. D" j( L  K) \! h
程序代码* w  R% h) h! D/ {. H7 }
1) public string[] Split(params char[] separator)4 f7 F% ]3 J$ L# ?, J0 j& k
2) public string[] Split(char[] separator, int count)
7 K% c( @( R& |" @3) public string[] Split(char[] separator, StringSplitOptions options)/ Y7 G3 H1 \( Y6 G- w
4) public string[] Split(string[] separator, StringSplitOptions options); J2 d4 M3 S! w+ ]* Q8 y. ]% N
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
0 x. s% p  }! Q  U8 a: T" D6) public string[] Split(string[] separator, int count, StringSplitOptions options)' P) a7 W0 {5 R/ ~. D

8 J8 V, f! E1 ?下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):6 l+ y4 s' j2 F( q7 m7 @
1 K! v* ^+ J. f
1. public string[] Split(params char[] separator)
( p5 X; p8 S; w! r- J1 j2 v6 Q% l& c4 c- |8 C: `8 l: z; \* [
程序代码/ h* H# y7 c; _9 C
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
, i( ]' K7 G* p2 qstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
4 L6 @+ C, M7 _( x( `+ b+ I; y+ B
2. public string[] Split(char[] separator, int count)6 W# g: f! c# E6 a1 X
% g/ v/ T! w3 s% y
程序代码
( I! \, }' I5 f* o- M1 k( bstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}2 A1 [' A( s2 z9 Y8 j
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
, O, o% g; H) R: ~. V8 A+ w' m& x9 w+ x& s* d. M3 D7 o
3. public string[] Split(char[] separator, StringSplitOptions options)4 t7 P: x% \$ h6 R- v, l

6 K9 n% n7 q" t  T 程序代码  F  P) \: f; g+ k% X
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
8 z6 G% C1 x9 N5 Ystring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& |1 H4 a. N/ @. W2 E
& P- n9 g  U2 f  u4 K/ F
4. public string[] Split(string[] separator, StringSplitOptions options)
& {4 P4 Y; ~1 S0 ]: J2 p% {2 O+ |, c+ h
程序代码) z# Y# X( n" ^; f
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素) T# w$ @" y" D6 C/ }
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素- e8 f* o) G' Y/ q

5 W4 t/ [3 R2 d/ j5. public string[] Split(char[] separator, int count, StringSplitOptions options)
* A' x  L; u/ y$ j6 M% V! ?8 N  Y* V$ f8 W/ P+ Z( T
程序代码
  n5 ^+ X3 A! x0 fstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( Z+ v% d* {* s9 K5 ]string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素) ]0 p$ A5 A# x! R& h' e; c1 `
! |5 n- b4 M) o: M
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
6 g$ d% W$ }) S4 R2 b3 j& J: D' R( S1 D7 ~
代码/ z8 F! H0 o6 u9 Z
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素) m/ X9 c6 h: R: m5 {) k
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-1 05:22 , Processed in 4.085118 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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