莫言科技

全过程、自定制,轻松实现跨 旅游集散中心自助游

票务与调度系统(独立版) 整合旅游集散中心资源,提供 自助半自助游自定义套餐

面向有志创业的人士、基于云 计算理念提供的创业产品

敬请期待

查看: 2906|回复: 3

升级程序开发——读web.config、执行sql脚本-凯发k8官网下载客户端

[复制链接]
发表于 2011-2-18 17:28:54 | 显示全部楼层 |
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件1 o0 r/ a1 }1 ]/ l
( {( a! h2 _/ x  z
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
* y. p3 t* c2 p- n i7 r" h
! c' i* c. o) u! e( p5 d$ g5 }; w: \/ l对于脚本文件的执行,通过“go”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
 楼主| 发表于 2011-2-18 17:33:01 | 显示全部楼层
这里是参考的这篇文章的做法,但是,这篇文章是用c#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
, m0 z' ~5 v! u: v7 q( c
 楼主| 发表于 2011-2-18 17:37:45 | 显示全部楼层
下面的这篇文章,介绍了split方法的各种重载的应用,并有例子,字符串切割的话可以看看
5 x( @/ v" z) j7 t# q, o! b. j7 {$ b2 e. u

5 y8 p7 a" ?8 a' o' k9 [' d1 f程序代码  b2 _; }& j7 v- e3 h- w2 q1 u
1) public string[] split(params char[] separator)
* v7 |' i) k5 |$ o( u2) public string[] split(char[] separator, int count)
) m* g' h7 o* i' j3) public string[] split(char[] separator, stringsplitoptions options)) ^' d% j9 p2 j" e s1 x
4) public string[] split(string[] separator, stringsplitoptions options)
4 g- o5 @/ s% m% e/ [7 o, e5) public string[] split(char[] separator, int count, stringsplitoptions options)
$ i& s  h$ v. x4 w4 u0 @6) public string[] split(string[] separator, int count, stringsplitoptions options)0 }8 z, |2 p! e u8 v

  e- z3 r1 u! z1 q6 x- g下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, _% z l8 ?8 e1 s6 `4 _
5 g( q& a0 d/ k& ?/ v0 p" j
1. public string[] split(params char[] separator)
% ?8 r. t0 n2 l" ]* d; i' ]9 p! y" t& y* r) x4 r) {. j0 g
程序代码7 b/ f* c9 e. h! @( j5 e1 z
string[] split = words.split(new char[] { ',' });//返回:{"1","2.3","","4"}
4 [7 q& d4 o/ w8 s' t. fstring[] split = words.split(new char[] { ',', '.' });//返回:{"1","2","3","","4"}
% m6 k9 [  u  y: `4 g
" h% h- t% k/ w4 }2. public string[] split(char[] separator, int count)" g2 v7 c( n `9 \$ m' j; ?

0 s0 v& o/ s  p; p1 t% d" p 程序代码% z4 p# l  x% d3 j& a, i3 a( p
string[] split = words.split(new char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}, ^$ m9 b3 h' h: a' f
string[] split = words.split(new char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}0 |, t; j  r# s. o; v: c% s

/ f4 a" r- v7 c: f, b* v3. public string[] split(char[] separator, stringsplitoptions options)
8 a& ~0 {/ s3 ]6 j: p/ {
" s# g( b2 e: h) u4 q& ` 程序代码
9 e$ y p% g2 n0 l9 h6 g0 k6 s# ustring[] split = words.split(new char[] { ',', '.' }, stringsplitoptions.removeemptyentries);//返回:{"1","2","3","4"} 不保留空元素  i$ \1 r9 i9 ]9 r7 z7 k% g9 t
string[] split = words.split(new char[] { ',', '.' }, stringsplitoptions.none);//返回:{"1","2","3","","4"} 保留空元素
$ [  j; r. ~, x: @/ t9 m
0 h" n# i2 v1 s1 z4. public string[] split(string[] separator, stringsplitoptions options)$ @/ u/ k8 ? w8 k: q
6 ?6 j* g  m6 `9 t$ l6 {
程序代码% d3 d3 a; ~( b: u* o
string[] split = words.split(new string[] { ",", "." }, stringsplitoptions.removeemptyentries);//返回:{"1","2","3","4"} 不保留空元素( p5 p7 v1 z4 t$ q
string[] split = words.split(new string[] { ",", "." }, stringsplitoptions.none);//返回:{"1","2","3","","4"} 保留空元素
' p: l! k- d r, i% c, x
$ s% u0 b3 t( d) _) g* v. f- j0 e4 |5. public string[] split(char[] separator, int count, stringsplitoptions options)* `, v" m* `$ z3 d4 r. o0 e
- n# j% z6 t; a$ v" d e# m% p9 i
程序代码$ l# [0 w5 l6 c" o1 j% g
string[] split = words.split(new char[] { ',', '.' }, 2, stringsplitoptions.removeemptyentries);//返回:{"1","2.3,,4"} 不保留空元素2 w& e, ^" h8 a$ j' j: e. v& d
string[] split = words.split(new char[] { ',', '.' }, 6, stringsplitoptions.none);//返回:{"1","2","3","","4"} 保留空元素
% h3 ~0 v  g! a5 @6 ]- z# f" _) h# m
6. public string[] split(string[] separator, int count, stringsplitoptions options)8 j0 h3 i( p4 |2 f
# s2 z! g2 v" |
代码
0 b* e$ [( b4 f  `string[] split = words.split(new string[] { ",", "." }, 2, stringsplitoptions.removeemptyentries);//返回:{"1","2.3,,4"} 不保留空元素' \/ b# y8 z! z: g6 a. m w
string[] split = words.split(new string[] { ",", "." }, 6, stringsplitoptions.none);//返回:{"1","2","3","","4"} 保留空元素

||archiver|莫言科技 ( )   

gmt 8, 2020-9-5 20:11 , processed in 0.060550 second(s), 11 queries , wincache on.

powered by x3.2

© 2001-2013

返回列表