晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
# P6 {% ?. y: h2 `
6 H: t3 w/ J& Q! W+ H; P4 U8 ^读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
; g; c! Z' A. Q) F0 `' L1 g1 R/ V; R+ H) R* z7 o  {0 K5 P3 B/ i* N7 T' Q
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
  S' T5 A) ^/ p, Hhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
$ f- k# O* h: @4 Y6 M7 [/ Z9 [http://www.itwis.com/html/net/c/20100506/8234.html  s0 O% K$ a: l5 l

3 C) H7 b& w6 V; }; O9 K, T2 ~" K程序代码+ d8 W8 [) L) U* W/ r# k2 v
1) public string[] Split(params char[] separator)
8 w) f" C3 v' m* A: C2) public string[] Split(char[] separator, int count)
1 v. ~9 V+ }2 X. O3) public string[] Split(char[] separator, StringSplitOptions options); r# ^6 T7 G' `: }+ ?
4) public string[] Split(string[] separator, StringSplitOptions options)
2 w9 C" Z! @" d+ y5) public string[] Split(char[] separator, int count, StringSplitOptions options)
2 J$ M  O$ C( F* C/ H) j/ ?6) public string[] Split(string[] separator, int count, StringSplitOptions options)
) n" q3 `& ]; e9 k! R
0 b1 D7 A. k/ K, F8 |6 k下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):. C3 H4 ?  O1 L

' {5 Z: }! A5 D. s2 N, Q9 a- I1. public string[] Split(params char[] separator)
* d  y( p; d$ R+ C/ }! `- a9 i+ N! [' u% ~) B$ m$ i* n; _
程序代码
* u; T  |( o: I( fstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
! x) d) |% V' k: N2 Sstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
! P: j: R. d1 ]+ v$ V4 g4 b( g9 h% {9 T: g; g" I9 E# s
2. public string[] Split(char[] separator, int count)  u$ X+ u3 ~; j/ f

9 M- k( h4 I$ l/ ?' f( n9 J, _ 程序代码
5 C) s& b7 O! ^: q  @8 {# vstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
0 S$ T( i& j* e2 O( Q) a; ?string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
) ~. l+ t! A# F7 n0 G* `" Q- s% u( _4 ]2 R
3. public string[] Split(char[] separator, StringSplitOptions options)
4 V0 K4 T' m4 G. [4 q( p
6 ~5 w/ M1 w( k/ T 程序代码
/ K7 a6 g( l/ W3 ^( `* k4 L+ R( Lstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
' @4 K# }( _: C2 x- F/ J! Qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 M+ w9 f- \5 X& n7 o
. Y) z3 I& w) a  M& q; r1 l4. public string[] Split(string[] separator, StringSplitOptions options)
7 |9 f, p: y, `* K
/ T2 ?/ `7 Z6 v4 f( n0 o" r 程序代码* C# l5 o) q4 d/ i/ m
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
/ a+ t4 l. A/ `: j& q9 j2 _string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素  ~6 L$ s) |) c7 O# F4 Y/ h* f
, q+ W# M0 l2 K- m( N
5. public string[] Split(char[] separator, int count, StringSplitOptions options)! u& p+ v$ U- @3 |; M

* x* a% m+ y" D# ^$ ~- w  u- I 程序代码, ?$ n; l% h: V) v; L: v+ W8 a
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
1 m2 J8 h. c: b0 U$ P& v+ a- d6 `string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& D, j$ R; L( E8 F% F

) C  `2 I6 @) ~6. public string[] Split(string[] separator, int count, StringSplitOptions options)
$ T6 @& k7 C. x  d9 E( o3 t8 B
0 O( v5 Y- j, ~3 a2 P0 T. J$ j代码
- O* Y+ I9 H" q9 w5 ~) _# ostring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
3 w* d2 q8 L8 |" n; |  Rstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-7 08:44 , Processed in 6.068948 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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