晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
/ D) D9 z& ]1 u( y2 _7 I6 z$ J
, P/ v/ h6 s- g读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
" Q/ R+ M5 Q$ }4 b* h, D4 z( w% b. z, d; ?; a3 C8 ?3 W% K8 b6 \
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
% s4 k3 d9 q+ d% Lhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看+ L2 S6 U* y( _* r$ i
http://www.itwis.com/html/net/c/20100506/8234.html
# X' e5 Q& q* h! ~2 ?2 c
4 ]% t5 H7 V8 w! O' x程序代码
  ^8 Q) T) s" T/ p1) public string[] Split(params char[] separator), I/ k9 B5 A3 C6 }8 E
2) public string[] Split(char[] separator, int count)9 S* k7 i( A. m! b9 k' z
3) public string[] Split(char[] separator, StringSplitOptions options)5 ~) D7 d1 \# C: Q
4) public string[] Split(string[] separator, StringSplitOptions options)
# T! f/ l' r: U. ~- W& Q5) public string[] Split(char[] separator, int count, StringSplitOptions options)
* b" N; H8 V0 S/ u) l1 _: S6) public string[] Split(string[] separator, int count, StringSplitOptions options)
4 k6 ?; z: k) y
/ N2 l; v0 y/ P; x' `; I# y下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
# J' a' P4 \3 z. b4 T# w8 N7 ^
) [$ S8 J3 @9 I$ w1. public string[] Split(params char[] separator). [, q! ~! l5 _. O

9 X- T. }1 {3 _9 L. H# K8 B+ j 程序代码* |( M& n, E( s8 ?' `* a
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
/ {9 @( s4 N2 h% u" ], Q: M: Mstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}1 y$ k  U) a+ |2 g. g8 h( U
& U* X7 F  l: N# Y2 k- Y: x
2. public string[] Split(char[] separator, int count)
+ V( i! O, a, x8 ^  H; b  G+ F3 G  {- ]+ k: i; R, A! m6 q2 ^/ S
程序代码& J: S, k  O: D' s* [$ ~) }7 o
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
1 e# i) n- g1 o8 ~' m  L0 i: zstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
2 R( e. S- H+ E8 W! r  D9 v0 O: k3 \
3. public string[] Split(char[] separator, StringSplitOptions options)1 u/ q( \* W. n
7 H) b$ ~' @( `0 k! K: L7 {. l
程序代码4 \4 E; K. z. P+ p$ T! G
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素8 x) p; v) T5 r
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
& z# ]4 w+ a9 x' z2 k/ ~
3 M8 L7 e$ m+ C' t  b9 z5 ~4. public string[] Split(string[] separator, StringSplitOptions options)
1 D; C& ~; R3 G) Y& G# g9 |4 w% _- n
程序代码4 G1 f1 m9 t! o+ ?8 L: X: G
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素% L: d( ~% k! b9 |1 o+ n, E
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& |* f+ Z" F' s8 y, M: u' X% _

1 p; F7 }. I/ q5. public string[] Split(char[] separator, int count, StringSplitOptions options)/ {  k7 u; k1 R- F/ k7 e5 B/ v. Q
, r  c# S! G% d! @+ a
程序代码: q' m7 R/ }2 U' h6 j; K  P
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
9 E% c, X/ Q) X7 C6 f# p, `string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 ~/ Q5 y* j& \1 ]2 ^
6 F0 s# t6 J9 J5 |+ U
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
4 e6 s, n7 }  {$ P6 F9 t
# D; R6 v' [6 ~. M1 J, w4 |) A  f1 D代码7 g; ]  U8 y5 w
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素* H2 i/ }8 |( ~  O; q
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-31 20:28 , Processed in 6.068593 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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