晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件( b/ A; b" j  u$ ]
3 g7 X, N$ D+ n
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
# }, Q! Z6 B: \& h1 ?; v: M: B$ R: m  {# X: O: h
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别% f5 v* V- F  N4 J; g
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
' c2 k/ k# D4 Y4 ahttp://www.itwis.com/html/net/c/20100506/8234.html
( I$ `6 U& ?3 H8 t2 S  C
5 [9 T0 ]7 r5 [3 |3 A1 L程序代码
* f$ o0 i* g  S  K0 x" w1) public string[] Split(params char[] separator): l# x; T! H+ C5 W4 o
2) public string[] Split(char[] separator, int count)) a+ H/ Z  P3 l. _/ P
3) public string[] Split(char[] separator, StringSplitOptions options)0 M% ]+ p( c, J  j
4) public string[] Split(string[] separator, StringSplitOptions options)
4 b6 \4 f, G& d. [) y" h* C5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ Q8 m: j8 y4 q6) public string[] Split(string[] separator, int count, StringSplitOptions options)9 O3 V4 G+ @0 L" p( A( n* e
% q# @! i" T  e4 P1 b3 T
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
" u9 P1 a7 S8 e  I# D' c
) D' h- Z9 L+ X1. public string[] Split(params char[] separator)
3 R, p3 _" P$ _2 ~9 S4 m
1 L5 `2 f7 f/ J; p1 u; p 程序代码
3 w$ Z  o+ w' Ostring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 r9 j: `) s3 r4 K
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
& B" i% ?2 r- E* T0 S/ H7 [  x
  h7 t7 ]0 |7 _+ Y! j6 d2. public string[] Split(char[] separator, int count): s( c  z4 y$ _. @
0 J6 C+ R6 p  O; @: `' f
程序代码
  h$ u! Z2 j  j3 V* C- Q( x! v; wstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}' D/ z1 g) c, t5 f
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
! b: `0 J% w3 v) W' }  L' k$ Z0 }6 [
3. public string[] Split(char[] separator, StringSplitOptions options)4 x" s# c; }& q6 o$ M. v
9 O/ ^* F& ]+ V* n
程序代码: i3 w. `+ x% w7 Z6 ^. b  f  K
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素( L: h0 H1 o. b/ a+ n+ G
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( N0 i, O, D8 Z& p5 b1 S" x& }- Z2 `- Z- Q9 s. H8 ^1 B& v
4. public string[] Split(string[] separator, StringSplitOptions options)
0 R) j+ K, p: r9 A5 l1 G- N) i' `6 J7 Z! Y
程序代码) R% {* _; e( K  X: m- R
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
, E) x2 J" y, V' D: m; w9 d; Fstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# N. H- n) A/ a. k7 o
9 P5 W# q+ X, R# N3 V0 Q
5. public string[] Split(char[] separator, int count, StringSplitOptions options)% h9 N$ c% `, V3 j' A1 c2 t  G
) n; C! ~4 n2 U7 G8 j
程序代码
$ O- w5 G0 S% b* `7 @- N" Dstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
: a  h) g- T9 Q; y* Zstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ H: s/ ^2 D9 I  A; {9 b

5 U0 T5 D2 D( W; ?6. public string[] Split(string[] separator, int count, StringSplitOptions options)5 s: C. N  n1 U+ N; o

3 g3 ^* A( _8 I" u4 ^8 I) z代码
/ Z5 o; ^7 v6 J2 n, astring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
' h8 k' f& m5 D, F9 v2 `string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-27 02:16 , Processed in 6.064686 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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