晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
2 q+ K. S0 [5 f' e
* c9 F1 i0 Q# _6 ~) m7 ^. E读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码4 P8 H+ Q: V, m& j

9 ^: N5 `3 c8 d! {5 w5 ?对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别8 ?. n) a+ p! u, N6 T0 [3 H9 i
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
5 v& d& N2 j5 Vhttp://www.itwis.com/html/net/c/20100506/8234.html
+ V, I. C0 \7 e) V$ M1 L
( R$ q2 D# p- ?- o程序代码* O4 }% \2 i1 _4 k4 J9 K
1) public string[] Split(params char[] separator)
! z. j* }' X6 P5 U3 _* k2) public string[] Split(char[] separator, int count)
3 u& c- K5 X, W  d7 c% M5 t% S3) public string[] Split(char[] separator, StringSplitOptions options)) _7 Z, u1 f8 }" Z8 K3 b! W2 W
4) public string[] Split(string[] separator, StringSplitOptions options)7 Y" a: k4 S' ^1 B1 k
5) public string[] Split(char[] separator, int count, StringSplitOptions options)4 N0 }3 w& v; R2 V: }+ T: N
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
/ \  Q" f5 x1 A
8 n9 g, H; m9 P- \/ r下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
3 w+ j9 x7 M4 M
0 k6 Z+ }- j; f+ p, ]7 P1. public string[] Split(params char[] separator)5 c# p$ m' _% C1 M1 T
: p2 ?- ]: b- |0 O1 k
程序代码
/ d* T! Q% y3 j3 c3 w* F" Fstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
9 f9 u$ {) \8 Z1 astring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
  B! Q  I/ N5 g9 U+ R# z% ^3 m! f- |
2. public string[] Split(char[] separator, int count)
- ~2 b, l1 j6 z' `* U; H  R. S4 V! S
程序代码
+ I! I( k6 x" Bstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
, W' N, i5 x3 I5 V5 dstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}/ W2 H  ]0 z0 C  P+ h

- }" A3 ?* I# |2 H* p# F# j. D! v3. public string[] Split(char[] separator, StringSplitOptions options)) g6 z) b8 r+ c% X
8 T4 I. Y. K+ i" B
程序代码1 a3 N' @- x) x1 `* ]% |- T& F9 J
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素/ i, ]$ W& @# }# C6 s
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& h  a, z, y; c+ B% j8 J+ B  C
! {7 Y3 B2 ^' B" P2 _! B  x
4. public string[] Split(string[] separator, StringSplitOptions options), y7 _% ~. R* R; `& |% \* j. m
6 J: v, C* J. d7 H
程序代码& r* ?/ q( l( n: F  r& |
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素, o2 ]2 ~9 N6 N9 n
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
/ w, F! _; H- ?& ^$ J! s, h( d% `  R
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
" {/ D1 k  g# k
3 H" D0 R5 R8 R& ^+ _7 W 程序代码5 v& B: E" ^0 {3 ]/ F
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( W# q; }' |$ G) [; N4 A
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 {' S6 [& L/ L+ l, @6 Y4 M
! o( n, v1 |' S8 \* ]! @8 e6. public string[] Split(string[] separator, int count, StringSplitOptions options)6 i5 L) S/ m) O
+ K  E  A9 v' A8 l
代码" E, ?( p% O0 }% C' ~% f
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 u2 d9 e) X- G' t% J' `) ystring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-23 22:12 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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