晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
' s  K4 X* E! I6 l: F, c6 q! r$ C
' _  Z' W$ n' ?& h9 _; F0 J读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码6 s- l9 c" V: G+ x7 P! x, b3 ^
' T6 O2 u9 G2 E/ ~
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别3 z3 j: G/ @$ b- s2 u! V
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
& }% k6 l, k0 g2 l. s+ B- C; qhttp://www.itwis.com/html/net/c/20100506/8234.html! G0 y0 Z+ z# G( @
! T6 f' C* \; `2 U6 e
程序代码
% @+ x0 _1 u& {- Q! U9 R2 |- E1) public string[] Split(params char[] separator)* O' M$ d( m# t  @/ O& Y5 {
2) public string[] Split(char[] separator, int count)
2 Z, @; N8 k1 R+ u( Y5 D7 F" [3) public string[] Split(char[] separator, StringSplitOptions options)! L) v8 {3 {/ M7 z+ z1 I' b
4) public string[] Split(string[] separator, StringSplitOptions options)8 E" F' q6 i  k- d
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
; C: J7 F% p2 M& d6) public string[] Split(string[] separator, int count, StringSplitOptions options)* C4 p- [6 E, W  @

4 p- m; D4 }1 M% n$ P3 G/ O* y下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):% p- e) t" G; l& G5 L

' f) V$ v/ G# K3 t6 D7 g1. public string[] Split(params char[] separator)! M7 R$ X' Q* G- a0 U; B
$ r# o) G. O  w
程序代码
: I9 [$ U7 Z0 U9 @% kstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
& b8 z( |3 z8 S6 e4 F! p1 Nstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}9 G3 D) v, L3 a' f7 i: }1 y

* S0 a  y9 `) ~: b8 Z2. public string[] Split(char[] separator, int count)$ x1 P+ a4 C" q0 k6 t/ R
* ~9 }! Y& H# D( @  W: `5 p
程序代码0 A, W7 F# n5 D* d% n: }/ B
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}- a* H/ F, u/ W. M0 G! Z  g% D
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
: n! A1 q( B6 k$ Y0 W
$ B% L( _1 L: o" ?6 ?8 K  I  e* l3. public string[] Split(char[] separator, StringSplitOptions options)
) `0 V8 m8 i0 |+ a2 G/ c
+ Q1 Q/ G  e! m6 g0 q  s 程序代码
, o4 f: D& S2 k. ?5 m# hstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素, u( c5 t8 M4 m3 E' t; N' P
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
! L4 j) ~# ~& L, m$ D0 @; G7 P) t' m3 s
4. public string[] Split(string[] separator, StringSplitOptions options)
# K2 b8 @& z* z7 q- b1 v; E% _: S& ]
程序代码/ R% I& ^2 V% {" C: [% J
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
  S$ J, }0 Q5 V% R$ Gstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素1 ?: H8 H) |# ~+ _2 j

! Z# ?; r+ w4 Y. E% A; \5. public string[] Split(char[] separator, int count, StringSplitOptions options)/ }8 F; v7 N' R! y5 K+ q1 n

" W, j' S% D7 B$ u$ e 程序代码
( a, b& ]4 r- C7 @1 L5 @: W9 f$ Qstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! @, `* K9 Q$ U( J' ~) M# v
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素! r; k5 B( ?6 C5 O

( o. m. U* z% S# B, {6. public string[] Split(string[] separator, int count, StringSplitOptions options)/ y( x# L7 A9 B* J+ k

! L* s: K7 c' x, G8 M代码% J' A7 r6 q# u* T! @- q
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
) P/ T4 N4 N, ^& `  c0 B8 Ustring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-23 01:32 , Processed in 6.069426 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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