晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
/ c+ q$ ]; f2 A: W1 R3 U8 X5 q; d3 e/ w; l  p+ _1 Y: a
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码* V. n1 W  b  T  G& Z
. G0 ]2 A: S$ _
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
! y3 ?4 h# v: c* C, v* {: yhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
+ s5 q* y, {1 o* V6 y$ `* whttp://www.itwis.com/html/net/c/20100506/8234.html+ v3 A9 }+ |8 M0 d

9 ~2 }- u$ ~8 d- t8 O0 y0 B程序代码, A7 ~% n. S7 T0 x
1) public string[] Split(params char[] separator)8 N+ d; t5 U- {) ?& X
2) public string[] Split(char[] separator, int count)
/ y& m6 v7 J& Y3) public string[] Split(char[] separator, StringSplitOptions options), k1 M( y$ U1 S
4) public string[] Split(string[] separator, StringSplitOptions options)
  |. K  j, E# k: r' E( [7 M) i5) public string[] Split(char[] separator, int count, StringSplitOptions options)
! F1 D  q1 ~+ p/ A3 s) y& m( `5 Z6) public string[] Split(string[] separator, int count, StringSplitOptions options)
0 @2 J2 j/ w' c$ |- ~0 t8 S0 y& n7 d) K; h: y, f+ E# E
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):6 @9 Y2 ~! K& r1 d$ P7 l8 R/ _1 \
, Z$ {4 E7 l( g
1. public string[] Split(params char[] separator)
, j0 Q# r+ N! E# g( w) B- H: J7 n8 |1 i$ x2 F# x' g
程序代码
8 c+ P7 z% h" N4 {/ Gstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
- l+ I1 E- B& x) t! t5 Kstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
! p( y  w1 u9 B9 Q' w  o
/ |- S% |. A0 ?. Y5 ]: K2. public string[] Split(char[] separator, int count)/ ~# f6 h& F- H9 g

9 l2 z# J- M( ]6 @- V 程序代码2 r* x" \* J1 z! d9 }: }
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
1 w# X7 c7 S( d; X, J3 vstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}# `/ e4 d; I' S# S: ^
+ ^5 L% [& V6 u$ e* }3 b
3. public string[] Split(char[] separator, StringSplitOptions options)7 P8 B) c" _& ?) K

3 P5 Y3 b/ @0 X. Z& ? 程序代码: p5 [8 \9 h3 }1 J& j! e
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素1 i, b- n& m+ k  D' H4 s
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ ^4 k: c+ z7 F8 f& ^, w, M
* d9 [  b) A- ~1 Q+ l0 @' a4. public string[] Split(string[] separator, StringSplitOptions options)' H8 ]- T8 W! q! z4 P
3 Z2 W  ~! ]' Y- }- }% K
程序代码3 C9 {7 ~; @# X+ `6 h
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素: Q2 H( x4 E( V3 J1 q. p
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% x. }, J  @% H5 L8 B' F
$ ^! y8 d/ T/ t5. public string[] Split(char[] separator, int count, StringSplitOptions options)! U7 c6 Z) v: l5 G; ~
7 c( j% |/ ?) ], c0 M; i
程序代码4 w& K: t" H6 ~, Y7 [
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! [# @8 u2 i, Estring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
4 c- o" Z( I/ t( o7 M
0 o# M: ]2 l" M6. public string[] Split(string[] separator, int count, StringSplitOptions options)1 T. u: s, C( m' `( u) u

9 J, Q( I, x1 |% v" e. v代码
, w  u7 [, g% d. N" t. ^' e2 q% t1 sstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
" k& x" i$ u; X3 W3 {4 U! O3 M* n6 |string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-11 08:36 , Processed in 6.068592 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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