晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
! h. j% y+ J- K: e5 p. I- _" p' h4 j( `+ F4 M2 U
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码% T; ?1 c; h/ U

) P, \2 @/ G/ l3 v$ f6 f对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别8 z& u  V/ \, U+ s
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
/ R. k6 l$ {1 |% w& F/ Yhttp://www.itwis.com/html/net/c/20100506/8234.html  o  ]/ G# z( g: Y; Y$ J

) ~: [5 j8 W$ ?! r& {3 |3 a程序代码
; F2 t% E) R, z/ T1) public string[] Split(params char[] separator)1 c# s2 u' e2 k3 C  H8 ^
2) public string[] Split(char[] separator, int count), X$ v7 e5 F" h8 k5 z' V9 M
3) public string[] Split(char[] separator, StringSplitOptions options)9 A9 o% j3 t8 r, L4 s3 b
4) public string[] Split(string[] separator, StringSplitOptions options)( @" E3 S2 I5 p1 T* m  ]& y
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
3 d) s: S2 x  d8 }6) public string[] Split(string[] separator, int count, StringSplitOptions options)
& S! s; K+ @6 W- p, C& E" F, w$ N3 c8 I/ f/ Y! @& e
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
# Q/ b& r3 {8 i. ~( q5 x: |9 n7 R- v+ d/ n6 ]
1. public string[] Split(params char[] separator)
, L, |% p: Z; v5 Y) O% E) y/ {# ]( C2 h* d1 X8 @! n- [
程序代码: Z& Z0 l! z; h6 D- u
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}% F; d3 @  z9 T0 G8 s1 c- ~
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
: h" z" k0 y; Y+ D/ B4 \) H: T$ P' N+ z$ V$ B0 K0 r" Z
2. public string[] Split(char[] separator, int count)
- W4 e9 [) |7 J( `2 d
& D2 o$ x# H: [% A  s* j) _) c 程序代码
! }, c7 B! D# e) wstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}  J3 B0 W. ~' k3 b9 J9 l+ _
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
# y! B3 U3 [# W$ I/ [1 Z& {  U$ \! R$ T/ m4 ~
3. public string[] Split(char[] separator, StringSplitOptions options)
& T0 i  n/ b: A6 J
$ _9 `" T; p% V 程序代码
* }3 |5 X* v8 s9 w) i  A) ~5 ^% B& ~string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
& U+ ^# u/ x2 W) Kstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* E) ^! ?& _, m3 O- N' t/ |, L  k8 ?% u6 J  u
4. public string[] Split(string[] separator, StringSplitOptions options)
" n9 O4 j# P( Z6 _/ G  ?
$ ^$ O2 F/ E% Q0 [ 程序代码
" G& Z! V2 d. Y4 [% o! cstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素! ^8 `! A) I  y
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ @; X* `7 V) Q7 J2 a' p3 e% G
$ e& z4 g# Y, }4 A* M1 i
5. public string[] Split(char[] separator, int count, StringSplitOptions options)% u; J: s8 `. T; |) O& P+ }/ Q

2 i; i- R5 J. o5 f+ g7 d! M 程序代码5 E4 Z) @" i$ w  A9 e
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
+ y2 Q6 h0 X2 p$ v- \string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素+ p3 s: S% c- W" c0 ^# K/ I. [
7 Q) J1 B9 E& c3 t( o
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
: m5 P( u/ j* }+ A$ H; X( h2 H0 A. f6 P6 B+ S. T
代码
$ |' @5 Z" p* |. r+ Kstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
2 b4 o3 H, f4 ^8 m2 @$ q5 d5 y, zstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-29 02:23 , Processed in 6.071877 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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