晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件0 a0 u/ [! }9 \- V1 b

8 K9 o  l* i0 e3 k读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码# p& B! E  ]+ Q% M8 F
2 ?- r, v+ I: `& i. l1 y$ x1 E
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别+ c/ B+ ?& S$ L" @% v
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看4 B" i& E8 d" M
http://www.itwis.com/html/net/c/20100506/8234.html/ l/ R; x* |) S3 o2 O" A5 h2 [1 L
9 S! c8 l- ~2 i8 T) C( ^2 a- U# z
程序代码
2 W2 k" z+ J- \- b" Q' k1) public string[] Split(params char[] separator)
/ v9 v9 _  S3 x( c. ^6 [2) public string[] Split(char[] separator, int count)4 K* Q, e8 P. p5 L: T, y0 I
3) public string[] Split(char[] separator, StringSplitOptions options)
( U! X1 x( c; J2 Q4 L4) public string[] Split(string[] separator, StringSplitOptions options)+ Y, m# i3 ?2 w+ s/ ?
5) public string[] Split(char[] separator, int count, StringSplitOptions options): _% c: h+ `* j: m6 D
6) public string[] Split(string[] separator, int count, StringSplitOptions options)  k; j1 M0 c' E- P; v
+ P4 g. X% k" Y& y8 D) s
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):3 Q" p  Q& f; M' A% H! g

5 S# W0 a$ g" J1 x" Y1. public string[] Split(params char[] separator)
  N8 Z# X' O1 E: L# ]0 l3 H' O/ M/ _4 \% p1 f
程序代码8 h) y: c# d% u% F* ~% m
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}; n( x+ d7 F! F2 _" A
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
% E( N" {* ?# I6 B( K; k- G0 S; |; }. |; r
2. public string[] Split(char[] separator, int count)
! a% C. \/ b# m9 v# `( y( R
/ r3 g9 m4 ?# T  s! j 程序代码. A5 T2 R$ P7 F/ [' k4 }0 b
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
# r0 `$ n; T# R( V- Estring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
) x3 A. Q* ~; P8 ]# s
) L( ?9 Y4 g; o7 O5 {/ Q, R+ l. [3. public string[] Split(char[] separator, StringSplitOptions options)/ b' s9 G: l0 d5 T
% _6 M5 R: J) s  Q9 n
程序代码/ Z. q# j8 A6 y0 l  H* ~/ u4 y# ]
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素3 i6 Z) [4 q1 \( [
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
  G4 p* G1 \& S6 ~$ w# J' o0 T' d$ W) N8 R; P
4. public string[] Split(string[] separator, StringSplitOptions options)
. Z% w  f- t& X" \
& b4 V' w1 X8 I2 C0 I 程序代码
& q* ?' z- O+ {: u0 Q( Astring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
6 l, U, J/ x$ O, H+ gstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 a2 y, x# Q" B1 n; a8 A# }

2 f0 n* m; O% a* Y5. public string[] Split(char[] separator, int count, StringSplitOptions options)* H3 I- y4 D6 B2 P
) z$ e' Y& u: m7 D0 E
程序代码. X" ~0 D0 b. X! A) S# ~8 Y9 ~* O
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
+ W3 I1 Y: T, {. ^* n3 e' Jstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 f% W, w. ~2 `
" e6 r( M, `8 M6. public string[] Split(string[] separator, int count, StringSplitOptions options)
2 z; A. n1 S) D. z, u3 E' n
; b6 Z! U# A6 _0 {代码
5 o9 u& t# x8 R7 S2 D% \) `string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
" F6 w4 \$ `( Z% s  astring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-8 21:38 , Processed in 6.062733 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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