晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件1 u. A0 \  N. F1 W0 f. n& E7 y, p
' i9 q4 V6 Y) @7 N
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码2 j& ]8 [$ {: x8 X' j1 J$ D

5 b7 @% Z! _7 ]6 h5 r对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
! g" s% P3 }$ z) uhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
7 n& j; \) P) P, }+ m: [http://www.itwis.com/html/net/c/20100506/8234.html
  d% t" B: A0 z. u) }
& T! }4 a, x- Q* M2 d! I程序代码, Z5 N7 u; X* d7 C
1) public string[] Split(params char[] separator)5 V- K1 o5 W9 f6 {* w. w
2) public string[] Split(char[] separator, int count)
/ F8 ~" l. ~; e. Z- O/ f3) public string[] Split(char[] separator, StringSplitOptions options)
% X! g2 j* X% h3 D4 W4) public string[] Split(string[] separator, StringSplitOptions options)
" y7 e9 l! ?1 q" K. D+ N0 `  O5) public string[] Split(char[] separator, int count, StringSplitOptions options)
9 _& I; I( K; g) g$ H+ n6 [$ c; C6) public string[] Split(string[] separator, int count, StringSplitOptions options)3 o& C  m; s$ v, D! c

* K9 k! }! a  f; U6 n1 x- L下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):9 I! y, s% ?9 v6 l: C$ {
0 [2 l9 D6 A1 I) r. D( ~
1. public string[] Split(params char[] separator)7 |7 X, P' c7 x( ?2 o- U

# c: l4 O0 n1 Q9 `8 |! M. U& s 程序代码
+ P1 o% L3 H8 y1 x2 r. pstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}+ e5 u5 a( o* `+ w2 l
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}4 d  U) B1 [/ S+ `( ]
3 _6 |9 a) D, K' k2 A
2. public string[] Split(char[] separator, int count)
" Y# S( m  W" Q. K
7 @- H6 g- w8 C 程序代码
# E9 W% _7 d# X; r' Ustring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
3 @+ l7 C7 y( Q/ ~+ A0 ?. y$ pstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}# B1 K" l. m3 E1 b

: d$ C; y1 N, m' C$ d$ W& M3. public string[] Split(char[] separator, StringSplitOptions options)! T; x* g5 A9 e
( x! M4 p4 Z% v6 S4 ?
程序代码
9 Q3 R8 y, {9 A9 ]string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
- d3 Z4 m. R4 }2 n% Vstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' G* e; A9 z2 c6 W4 C
, H5 Y* y1 ?2 x+ C' h  S% }4. public string[] Split(string[] separator, StringSplitOptions options); E  l4 n; t/ @  x8 G# D  \8 X: g7 L

$ S+ J, v' A) S3 Z$ Z+ ]) N 程序代码
( q; `8 E# h: ]1 Fstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
5 V" d+ h" W- Q4 s$ tstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 d8 |9 R( o0 u; x  s- Q/ \3 j% s& c) ]( [3 Y) m3 a
5. public string[] Split(char[] separator, int count, StringSplitOptions options)/ U5 P4 ~9 s3 ~- z, `

. j6 a( W5 w  r! r  D 程序代码
  q6 g3 R# P+ X+ |; g" Mstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素' @3 M: K% d$ {, w; M: q  D' d4 a
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素9 w% V/ V" M% x# G6 t- z$ l$ T; C
% W: U7 a' V' ?7 w" q0 n3 q
6. public string[] Split(string[] separator, int count, StringSplitOptions options); X/ b8 p, R$ v4 ^0 m

; V0 z: T* D! w; i7 U, @& @" ^8 m2 Y代码' s1 x. |: K9 k7 M7 d. C3 O% B
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! i1 M/ ~5 D1 G" e
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-12 10:43 , Processed in 6.069924 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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