晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
9 ~# w. H0 H) O$ D5 {- I4 V+ M: u, [1 M
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码" Z) r7 _' x% ?& _# R

1 h/ p* P% k3 \* ]对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别% e. Z- F8 O# J& i
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
5 X8 y! k7 s* _! K4 w( A$ p. ]http://www.itwis.com/html/net/c/20100506/8234.html/ M0 E4 k! F! F" }

% F" Q' R  h1 t程序代码
* _* l+ G% Q+ d4 ~' n. Z* P1) public string[] Split(params char[] separator)
7 w4 M1 t) Z# R" d: m2) public string[] Split(char[] separator, int count)/ b3 \9 Q' Z9 q% P' h4 K
3) public string[] Split(char[] separator, StringSplitOptions options)6 u0 N- Y1 c9 E2 u
4) public string[] Split(string[] separator, StringSplitOptions options)
1 \6 V5 b' ^5 S$ J. c5) public string[] Split(char[] separator, int count, StringSplitOptions options)
# U% q( q; e4 [. j- b! b6) public string[] Split(string[] separator, int count, StringSplitOptions options)
) @, U; e4 f0 u: H) F( s+ @3 q4 H' H, h/ A
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
" k! {! r8 W: E* d4 S8 {/ H2 c, M% Q* T* @0 d/ S
1. public string[] Split(params char[] separator)
) i. V, |9 m6 @* o; I
4 Y8 f+ j( w# ]4 L" k! n& i0 J 程序代码* F3 k* e; ~4 p0 ~
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}) ~$ K+ X" {5 `/ Q0 A3 G
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}/ X' n! ]9 p9 K: E' y* ^

: G& f$ R* g1 E! |2. public string[] Split(char[] separator, int count)7 `  Z  q( _$ {7 r
$ S: s' u2 s4 j# ?
程序代码
& Y% q) l8 |4 P' hstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
) F7 |/ U5 |4 K6 |& Astring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
3 H* k: B* Y. |
! e1 ~2 z+ Z! ?0 T3. public string[] Split(char[] separator, StringSplitOptions options): E; U  G8 i, W( W$ x
6 D$ n; |* y* b) @, H! Y" C
程序代码
: L5 y, ]; @; A0 ~) y1 f! N/ z( kstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
3 X4 I1 p9 Y7 {, L7 _- R' ustring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# \; J6 x; M+ D$ M8 w8 E

9 q* h1 B1 @4 ~9 Y6 }! ~4. public string[] Split(string[] separator, StringSplitOptions options); y. s0 {- k, D3 y1 m  S  t, a
/ s+ N( q, Q$ W# V+ S2 @
程序代码$ z& p' t" E# N& B5 Z3 V
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" g" w4 |. U) {8 fstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素- {! E3 K  f' P2 B; V& t+ [
8 m# g  A- T) ]. b+ P  [
5. public string[] Split(char[] separator, int count, StringSplitOptions options)4 A, `0 h  M) O; Q: ~

  y1 W' |* d3 H0 J9 b& K; l# t0 u 程序代码
6 E1 d! F* H/ J: a- ]0 Y+ G: A, Kstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! m- D0 P- k! Astring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
$ X& \% B  B& T5 P' ^4 L( g* {! T# {9 L0 R: z, S) n
6. public string[] Split(string[] separator, int count, StringSplitOptions options)4 M6 R9 X  n2 H7 r" m! o! a
; M/ E1 ?* [# C, b$ \& P
代码
  X$ S8 r% v! v! Pstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素4 p- l; f% A! P9 w) k( @- O. J5 C
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-7 07:09 , Processed in 5.157424 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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