晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件- o( l0 G0 E( T$ Z6 e
% f* j, V+ H, u% z+ h9 y  z6 i
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
; N* z% ^8 R+ h4 J- @% g2 [
( z1 Y) A. h8 o. j5 S, V$ R对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
8 N7 ~! C6 H! P) N# y) o& d3 ghttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
  i9 g5 q5 S+ a  K! r0 hhttp://www.itwis.com/html/net/c/20100506/8234.html
1 w  h! ]( \: i0 [2 o( w2 J$ E5 ~: [0 X
程序代码
+ k4 g: n$ J* ~( d5 Z$ `4 [1) public string[] Split(params char[] separator)1 C; e, V3 p& h4 o/ Q
2) public string[] Split(char[] separator, int count)
+ O6 U6 [: u! a+ s4 w3) public string[] Split(char[] separator, StringSplitOptions options): Q9 v, y0 c/ C! K5 C+ v
4) public string[] Split(string[] separator, StringSplitOptions options)" X/ ?  R$ X# J
5) public string[] Split(char[] separator, int count, StringSplitOptions options)* {& k$ k5 ^8 c6 O% n
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
+ `  ?( c9 e0 t  W8 {3 J$ H, T  Q. t3 q
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
  R/ {6 l, \: m: L4 r+ m3 j. j2 \  \3 U6 G. Q! i# j
1. public string[] Split(params char[] separator)
# m& u& m4 D& h: |9 m0 T# p- @* q8 |2 \# m( p0 f' p; z, M
程序代码
4 t& g9 m* W* Q% E! |$ @string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}- T2 @" I3 r0 F. {& G  I
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}/ i( ?+ ^0 k5 \5 D) O

+ T; K: e( ?- M2. public string[] Split(char[] separator, int count)+ R$ A9 H6 X' Z) y; @- ]8 n9 N
% P; N+ a& O# ]$ R$ s1 y
程序代码# o6 {/ r( k7 M; \+ f2 J
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}4 n! y% r& U0 z0 L1 }
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}5 Y; S5 L$ D0 Z/ Z6 _9 F4 S9 D
% x5 ]1 f6 Q; C% _* ~8 C2 e: ]* x
3. public string[] Split(char[] separator, StringSplitOptions options)3 b3 _3 q. @6 [3 [5 X% H' O8 S# D

5 H5 G9 |) q7 a* X 程序代码4 Q4 x- z5 Q; L7 N* U# J  d8 g
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
: ^. `4 U. s2 Q9 }. z# c, R+ wstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% g3 j* U0 o; W" R0 W9 m6 Z
- K; [$ F9 C- |! C7 a4. public string[] Split(string[] separator, StringSplitOptions options)% a5 e" {/ V8 I

9 G' T" x4 q: k* N 程序代码
* [+ m4 Q9 |8 Ustring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
& T$ e0 Y& |) i" pstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 j4 \* ?+ D0 e7 d; ?( b  u- Q" i+ ?
5. public string[] Split(char[] separator, int count, StringSplitOptions options)$ E/ G! E% G, O
% O9 q- }; N3 d6 K* }8 G
程序代码
, P7 ?4 R3 d$ nstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素. y- S/ k7 S4 x
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' d1 @8 X2 Q" P% r
! Q, t7 [/ t5 A8 P5 e6. public string[] Split(string[] separator, int count, StringSplitOptions options)0 l% L) p( e; w, Y  L! B

$ Z5 R/ i$ C  k7 Q代码
: A9 @9 q* ]3 \string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素) F8 c5 C* n; V* E+ h
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-20 18:29 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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