晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
& _  o- T! V7 q$ d1 M! r1 U" k' O4 t! y
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
( h$ f% @% m5 H1 k  H) W8 i" J( Y+ z5 G( @( c
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
9 R$ d7 t' q* |; p3 U2 T# h/ F) lhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
3 i7 N2 ]+ [& k/ l" mhttp://www.itwis.com/html/net/c/20100506/8234.html
. c1 J& p5 Z6 ^. Z0 f3 h
) @" T& v8 h8 Z) `0 m, t9 e& O程序代码
" }; L5 I6 p. q( a5 Y* I! d1) public string[] Split(params char[] separator)0 F* @. @& Y: y( z% k' F
2) public string[] Split(char[] separator, int count)
9 `- k& s7 V4 |3) public string[] Split(char[] separator, StringSplitOptions options)! K) c) x" W+ k; E+ {9 t$ X: t+ Z
4) public string[] Split(string[] separator, StringSplitOptions options)
6 }+ m7 r  O( W/ J# A5) public string[] Split(char[] separator, int count, StringSplitOptions options)
" [/ I# N. o2 d6) public string[] Split(string[] separator, int count, StringSplitOptions options)
) t3 W- p* S  j5 e( B/ S% e8 c0 j- ~( C: w' k
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
- D* S/ _: g, R: @2 \' {/ f$ v$ i- P* p+ S# ^( O% E( _* B
1. public string[] Split(params char[] separator)
9 Z' n6 [! W+ }+ T6 ^/ j0 p( i
1 G! e1 o, k- v& w 程序代码
) G3 g, d: F! M# M- Mstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
7 R! s0 w: p; `6 |7 l+ k3 {string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
& y* V( t' t! \# k' y$ O8 O, h. E0 G
$ X0 W# I1 K8 b( e2. public string[] Split(char[] separator, int count)& s; P( a0 n* x2 Q$ Z7 c& S7 \' H
, H) o  S9 c" b9 c) [
程序代码
3 Q6 L0 J% @! \; }string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
0 ~) e0 e; l$ z  Istring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
3 m, K# j. W0 w! k$ S) |- k
$ v6 G1 R8 j6 c1 s0 ~. L) C# @1 c3. public string[] Split(char[] separator, StringSplitOptions options)7 f- }3 H) C7 ^7 ?3 R2 h! z' |. _
: \: N# G! b( m2 `
程序代码
8 C! P- f# Q" M) Fstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素- Q/ E. j# n# T# e, s2 W0 U, e
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
9 Q& K' D4 |) T8 ?( u: y; L- G) ?2 Q$ r2 f, F
4. public string[] Split(string[] separator, StringSplitOptions options)2 }5 t8 |; X9 @. S
( E/ E+ E) l6 l" G. x$ R% ~
程序代码( b* {, J1 A# A- l2 X* j: H
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" \! \( S6 w8 o) ]$ P$ astring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# e0 L! V& `2 P2 e) I
6 H, X2 M9 z- A5 U0 r
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
/ ^. _  g; j; B. _$ G
* C( p: A- Q, {: r7 ^, | 程序代码
, d) X. \# N& jstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素2 f: U0 ?' t2 w6 ^6 l
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素9 t4 W/ r8 v$ N7 y
, S8 [. w9 w3 y3 O0 k, b/ V
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
& W; V+ M3 t5 r: w6 R" a: Q" ^8 G4 @
代码9 B' [7 ^  d  ~: I# ~: o* {
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( t' h6 I( U+ W
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-8 13:34 , Processed in 4.068515 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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