晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
, O0 @& j5 v  R; V. n) K- M  j/ v$ S. ^5 n9 W  u0 H
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
8 {6 ]! }7 z) Y
# [( }' F6 `- {- g对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
, [# z3 M9 a* Khttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
: ^' N. _' c9 P/ [# ?3 ~http://www.itwis.com/html/net/c/20100506/8234.html- w) i8 o; b& f6 [. t! G
7 u; m3 T) o5 A- t; D# c* L
程序代码+ g! k3 t7 N7 R5 D9 N" Q$ X& B. t
1) public string[] Split(params char[] separator); A: s/ r) a* I- Z1 O
2) public string[] Split(char[] separator, int count)( O9 Z8 I4 G7 T  k3 Y
3) public string[] Split(char[] separator, StringSplitOptions options)
, I- L8 _: @+ Q! r* I4) public string[] Split(string[] separator, StringSplitOptions options)# E+ x1 a% T) h) x7 \
5) public string[] Split(char[] separator, int count, StringSplitOptions options)$ G8 Q3 q) Y! N9 k) \; X" R
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
, B1 t2 I+ s  Q+ b  I7 ^' ?- D, M+ |& b1 X4 K- M0 d, n
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):" I% H1 A' n9 n" S9 Q  \8 x
. t; m1 n9 {+ @4 M6 A, C
1. public string[] Split(params char[] separator)
- D9 _+ E3 ^# {+ A
9 i* L+ K+ Q& Z 程序代码
  j' B9 L, Y& Xstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 H) G  G& v6 x( G
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
! Y" s: S# L2 {% k. ]9 J7 T/ p5 S$ p
2. public string[] Split(char[] separator, int count); }- ]0 s4 q- u+ q# }6 C& Y! k
( Z$ r( B2 P0 w
程序代码
) h) `1 P6 f  }) m% l+ _string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}4 r/ o0 I$ o1 g9 p
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}* v( H1 y) j$ o+ P! _" M* _
( Q! B, c) |& Y( n9 ]1 |
3. public string[] Split(char[] separator, StringSplitOptions options)
' b6 N9 z: ^; Z" M% o
- d! |* G0 [+ O8 K9 t  D. b 程序代码
; V1 J! }3 z! |8 B/ Estring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素- o& a0 w6 L' |9 g* S
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
) j, C! _# X) [3 M- w; b
/ l6 w5 ]& D; ^- X, `6 r0 U" f, ]4. public string[] Split(string[] separator, StringSplitOptions options)
3 ?( a1 Q1 G$ T
% H& y3 P/ A  W" w 程序代码
1 ]1 g2 c) f* Istring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素8 Y, [8 f& ]. R! z; E4 x  j  O6 Y
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素: Y- B, b' l& f3 ?5 S
+ g' f8 T3 L4 S" y1 V9 W
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
: [0 ?  j* y) J, K  R- X9 n5 ^/ l* ^6 l
程序代码) a; l: _6 U+ f2 Z/ R0 i
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 V- E: X4 \6 t! p: I$ J0 T# Fstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
) I+ q  F8 W; o' q8 a$ L" ~# G5 q/ v% A
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
/ c) B, _; E9 ?; Z, R! T) {  j6 ~" @0 D5 Y( F% ?
代码
- \8 n, W( }; b8 V* dstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! h8 i, k! P: P+ O- [: \( Q* V2 a
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-9 13:42 , Processed in 6.070901 second(s), 10 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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