晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
& t; Y2 ~5 @! S+ u$ L8 J( M' m' o- S# y8 n- _( q$ E
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码7 ]. p1 V& H; Y0 l. F
$ o# {  H! i- E
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别4 m3 K7 ], p$ z7 e
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看0 u* [9 v8 H7 g$ `1 ^
http://www.itwis.com/html/net/c/20100506/8234.html3 E1 i9 f) ?8 v/ q/ p

/ L6 q2 v0 }4 o2 M+ h/ L0 p程序代码2 A; V5 V& H0 p8 M7 i
1) public string[] Split(params char[] separator)# C! D! ?& Y; A) o) B* A5 ^, A7 N
2) public string[] Split(char[] separator, int count)" v: x4 x) Q; S- X* \" d4 e
3) public string[] Split(char[] separator, StringSplitOptions options)
2 ]5 ^/ _6 u; N: U" [4) public string[] Split(string[] separator, StringSplitOptions options)! S* x( A: {% z
5) public string[] Split(char[] separator, int count, StringSplitOptions options), N3 x) p; {; s, n' |( ?
6) public string[] Split(string[] separator, int count, StringSplitOptions options)' G/ @' x. _0 D6 B- v  N, ^$ p; @
/ n1 x1 H' U! B% `6 K1 `
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
! @: a" _  ]0 ~: ?- t9 A% `7 B$ `$ y) X1 K8 @. F
1. public string[] Split(params char[] separator)$ Y& ^8 q, k' e

' R: [. ?0 I1 M 程序代码! a! ^$ u" V. P+ k/ O) @
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
. x1 B) a: ?* Y! Q0 W5 o5 J+ Dstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
8 r3 b% r6 M" r- _$ L! i: T  X3 n2 E! t, A9 F/ V2 U+ y3 @2 r
2. public string[] Split(char[] separator, int count)' n+ Q8 ]: @7 S0 k# `: G
2 {+ J# }: ^6 q4 f
程序代码0 I1 e$ Y* n  e; U& W% o0 Z
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}0 I, j( C! B7 R" [
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}$ ?6 }' s& v2 g6 U; A
" J% i  @" q2 N5 [6 O" |
3. public string[] Split(char[] separator, StringSplitOptions options)+ |: F1 j7 D$ q, c, m5 N8 _+ b
6 e! \: {# d, p* p
程序代码. J: @5 {8 U7 t$ u
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; d0 {6 @9 o% R; x& Z# w
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* N3 h. r, M( a$ z
. x# C7 d/ o2 h4. public string[] Split(string[] separator, StringSplitOptions options)
) ^5 ?) U- U, L  q* d' H. H( Q$ F' T8 U
程序代码
& W8 b: o2 v! V4 o5 Dstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素. ^! H0 z5 p: P7 e; k# H
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素- r% B6 k/ j& ?0 U! h
% K3 {, j5 L& T" T. m
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
' Q0 G+ C+ R& F5 t$ [* O; t$ H
1 {! T. v9 ]9 l) A) N* P 程序代码6 T1 w* P& i$ ~# x! E  m
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
- _" N9 l: f5 W. f3 ^9 C2 {string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 I! y1 M4 E, B* F  M# R) b5 B3 p0 s8 c5 `3 q) q! |, i1 E
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
0 B" S6 P; S/ |( o; \7 y
( s) j% Z9 b) P# x! {, m; n  X代码, T5 V; v2 Q9 J, V' O: ]
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素8 ]' q) U; X6 {0 B+ W* q8 v5 C
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-27 09:56 , Processed in 6.065663 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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