晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件- `1 `0 s, T  T1 l

2 y; t; y+ ]8 G9 f8 {读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码7 `* N1 g. s. U
& U+ c. p7 P% h
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
9 G. A- `! d( U0 j5 o: K) lhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看0 ?2 B! ~0 L' r: @
http://www.itwis.com/html/net/c/20100506/8234.html
6 S/ s9 p7 J0 z
; I2 M3 b( H- V程序代码
% X4 K, v! W( v. }6 x+ X1) public string[] Split(params char[] separator)
4 r, F. C% ]' H9 g# F7 f5 w* c2) public string[] Split(char[] separator, int count)7 ?7 w& f' R2 A/ K2 E6 C
3) public string[] Split(char[] separator, StringSplitOptions options)
* h/ T. ^" s8 e" Z# f; w  Y4) public string[] Split(string[] separator, StringSplitOptions options)( D* {1 h1 B. S8 e5 }
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
! B. c. ~9 P* ]2 h4 f; j6) public string[] Split(string[] separator, int count, StringSplitOptions options)* ^, B& n; k" t! A9 |% q
, b+ z  T. }  Q# T' ^) Z! |
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):: ~8 g9 B  Q: O4 C' |

0 Q( p+ q$ `6 G& A9 c6 N1. public string[] Split(params char[] separator)
9 S2 p- m: b5 R$ {5 w1 f5 j- n& N
' t8 z+ [: {  c7 ~9 c! \6 {3 C' U 程序代码; O* H/ l5 ?9 j3 I: d, p$ m
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}) I: e, H& O# n8 s: {+ U4 \
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
! ?* b7 Y" W% Z0 [" V" M: W5 T5 I: y% I& C6 ?
2. public string[] Split(char[] separator, int count)
0 {" z% Z7 B2 E$ D1 E) {- B6 O1 ?1 i# G! O
程序代码& S$ g* C* x9 [6 q, `# m2 o
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}# I; L0 ~8 K, u7 F3 d
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}" C( I4 C0 B, N1 A5 F3 x4 [# b

9 E$ @3 m  y7 J, X* \2 s8 x3. public string[] Split(char[] separator, StringSplitOptions options)
$ D% [* J1 `/ u5 o* K6 P; {7 B! D0 D' O: o6 j9 q
程序代码5 b0 \9 a5 _* n6 g
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
5 n9 f' `1 Q! z) Vstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, k) a5 i0 b, Q5 D5 k% @

( v3 ~. q2 k; D4. public string[] Split(string[] separator, StringSplitOptions options)
+ `2 K  R, ~2 |) {. c: V' O- H1 I4 C$ F: ~4 F! T
程序代码
' e  G+ E' B. [2 Xstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素* W2 l! d: `$ ~( j
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
1 A/ j( Z  O8 V. {0 @2 K
+ c) U1 a  T) e; F; g5. public string[] Split(char[] separator, int count, StringSplitOptions options)- l( F9 M3 ?9 w. c8 f. W2 z" L6 Q( X

& X  |1 c% |; x& h8 g0 L# @8 h: E, J 程序代码
5 d/ ~: F1 s! n; Cstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素+ M! m/ x2 j: k
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素2 J: @" L# E) U5 `7 O
$ _- g. a6 J$ `
6. public string[] Split(string[] separator, int count, StringSplitOptions options)- h- O) B9 W0 f
" s# {. M3 P/ C
代码
* ^* ^' q& Q+ w( bstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素% J% W, P- _% w. J* i
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-6 09:07 , Processed in 6.066639 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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