晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件, Q% ?/ U' T8 k# t5 d) D. n
8 H- }4 Q1 t2 r
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
* {4 U0 b* j5 f
1 G' W, i" @- {' u2 j* n; y对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别4 m) H0 V9 y# I
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看/ \0 f4 v' }, z  u: g+ L8 E
http://www.itwis.com/html/net/c/20100506/8234.html
( {) ^; G$ p7 h1 b6 `6 D' }+ p9 e. H) {" o6 J
程序代码
2 p& t. z5 p3 }5 Q; T! m' R8 e1) public string[] Split(params char[] separator)
6 C; B( K' d/ ~0 _* P2) public string[] Split(char[] separator, int count)
# O5 ?! s' F0 Q7 v% k3) public string[] Split(char[] separator, StringSplitOptions options)) c3 _0 ^0 X' {) W+ ^
4) public string[] Split(string[] separator, StringSplitOptions options)
; {$ [- r! e; A1 T. P% H* o5) public string[] Split(char[] separator, int count, StringSplitOptions options)$ B) G6 D& i6 k- R
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
" i% C4 V3 g0 X3 r% ]5 c( U1 s
/ t- U% c& @6 I& d下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):" K; L! l  P" z& G$ y5 J
2 N  Y. R1 j) l! n& n
1. public string[] Split(params char[] separator); }2 X1 g- D* Y
4 j7 I: _8 {6 u* V( P; [
程序代码
0 J5 h$ c( d. m; c6 `8 X$ ystring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
$ g% f" l# r. [1 n) U4 V+ C. m4 ]8 Sstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
  M1 s: X) d  y7 J/ s3 R7 a
2 D- }' A6 D" f9 }2. public string[] Split(char[] separator, int count)
! j6 e  R) ?, R" S
6 E& N8 R8 `. ~, D9 d* B8 c 程序代码' N3 |3 k9 M' t7 ?2 H' O7 |
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}8 m7 M2 X' _& H( q1 p
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}$ Z+ V/ ~; U0 S% C! x8 R

1 C, r: p% U2 V) v3. public string[] Split(char[] separator, StringSplitOptions options)& U( g, c- C/ G& {
8 T: B' t3 M7 J
程序代码6 P$ L# r  b* U0 e  v# [5 P
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
$ N/ v% V  d) }3 b' f8 n& Y9 N7 C/ e( Wstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" W  d: h' P+ `
" E  ~$ g( E: l; {' |
4. public string[] Split(string[] separator, StringSplitOptions options)
0 P. u4 s! G# v  [  M7 F+ H
/ q" f/ R4 B: X3 p 程序代码4 Y% ]" ^0 ]) o: i7 q0 _
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素$ C' p- D4 p. u9 v
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: V8 d0 @9 T. i1 O1 A- `% }3 g. F. U- ]
5. public string[] Split(char[] separator, int count, StringSplitOptions options), ^8 \6 L' l* c! I" b

8 y) t! v3 B0 D1 G5 H- X( I; V6 R 程序代码+ ~  S' g' D4 _: {
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素0 N5 [0 E, d# L( P( M
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# R9 Z7 @  |. p; n
2 h) U4 g! e* c4 h6 S
6. public string[] Split(string[] separator, int count, StringSplitOptions options)9 n/ ]0 N$ X6 g: ?  g$ p
$ [: U) y5 A6 `  C+ }, h; R
代码
% ~- X* `+ E) [/ Bstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( r# n" k% V$ D  \/ w9 ~5 [string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-10 06:22 , Processed in 6.070901 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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