晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
( F' [0 W+ T* h: Y& e- w1 B
& c2 x/ ^) r$ v/ w读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码- Y: Y8 v7 i- U# J

. r$ R, [/ k3 P% C. f对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
# M% m" Y, o: Z. B, ~http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看; M6 ]6 p- b5 U" |  i
http://www.itwis.com/html/net/c/20100506/8234.html
2 t- H4 h$ G# l5 u5 F! H4 q" {* G2 L6 ~+ v
程序代码+ [: V1 [: ]4 i: V. \6 w1 x
1) public string[] Split(params char[] separator)
# h  v5 ~& {( A' E  H: Y2) public string[] Split(char[] separator, int count)2 _' Y+ b: B2 z0 a7 T/ c
3) public string[] Split(char[] separator, StringSplitOptions options)
& |9 u/ i% ?& l7 M4) public string[] Split(string[] separator, StringSplitOptions options): V2 T8 k$ T, y, }5 W
5) public string[] Split(char[] separator, int count, StringSplitOptions options)' R8 q1 K1 W2 [" m2 ?9 T2 l
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
- n$ {. E, P8 v3 O- e: H% {$ _* j! ]2 e8 P, j
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):4 n% G, x. @8 C+ B* T" a0 ?5 ]3 j9 B

9 k/ J; \6 H3 M) f1 q/ c! k5 \; ]1 v1. public string[] Split(params char[] separator)
, A6 a* b( P0 {- W/ x
! ]) Q4 B1 q) _6 U' N3 i+ E 程序代码
9 P* b& _2 K+ ^* O) }9 T0 n5 Wstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
. S* q( h) c; Jstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}+ {4 e6 R% z, z- z
6 k" O; m1 k0 _3 `8 y
2. public string[] Split(char[] separator, int count)
- R  Z4 ~+ b2 C% B7 T  v$ _9 b- m, r8 ]2 T. l; h$ u/ G$ p
程序代码
% d6 n1 Y, Z* y8 ~string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
% |2 L% f% Z6 i8 L! Ustring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}8 s2 e  ]) V) [' j
% w& T$ p6 C9 _  n2 B6 D6 t
3. public string[] Split(char[] separator, StringSplitOptions options)9 X0 C% J& y0 Y2 f; y

# J3 K& M; C* A" H6 X; a) M) ~; l% | 程序代码
3 e, m$ z0 B& s' H  Fstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素% ?. ^9 l5 n, Q8 V& u  B, ?# H
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# q# }) L! Z: @9 U6 i" Q. c+ t

( @, ~+ s. k  W9 r4 h9 }3 y* o4. public string[] Split(string[] separator, StringSplitOptions options), p5 Z( G; Y+ R1 v2 L8 C1 h, U6 ~& u
$ ~' A$ B5 F7 `
程序代码
* F9 x: `  j" ~string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素& I# |2 i2 B3 ^& O* P
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 ?9 h6 D7 i0 h, O4 x! J& S/ m% r8 y* ^/ v
5. public string[] Split(char[] separator, int count, StringSplitOptions options)  z' Q! D; u+ L6 o

& `9 Y3 y2 O" O+ A7 t, |' T5 R 程序代码0 A; H- d7 N2 A+ W
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 E5 h6 v- T0 rstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
4 D7 [. n9 D4 ~! c! U# Q2 t: B3 m" t0 ?+ a2 A
6. public string[] Split(string[] separator, int count, StringSplitOptions options), M2 g# u9 @% J  }* A, n
. K' u' L: j8 r; ?
代码
3 n1 Z( {, j+ X7 `. d+ o3 O, z# M1 m  ostring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素+ E% o. N7 E( I  C: C% W
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-21 06:48 , Processed in 6.072499 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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