晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
! i: e( Y! k5 `6 `( d( x
1 G7 e" {5 [$ U读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
* o  f+ M% d- T5 L1 M& a$ i3 Q0 o- M9 B4 k6 \( g2 E
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
* E) |) x; m) Z. Nhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看( R, D, H( W3 x  g8 i2 J) G
http://www.itwis.com/html/net/c/20100506/8234.html, l% J7 |7 v- l6 ]3 C
( M7 |8 E! t. R3 O( k
程序代码/ w! F* n' K' }: p; ^. l3 }
1) public string[] Split(params char[] separator)! e# D% n  q$ C( z7 W9 B6 ]7 j
2) public string[] Split(char[] separator, int count)
8 F  \; P: }& `, l$ q& m: y- f3) public string[] Split(char[] separator, StringSplitOptions options)
. J* [% k/ T0 w, {6 Q2 \4) public string[] Split(string[] separator, StringSplitOptions options)
; v; \0 t- W) ~1 E- V0 q- v" [5) public string[] Split(char[] separator, int count, StringSplitOptions options)& m% a% w4 ^3 J! I6 S9 z( K/ n
6) public string[] Split(string[] separator, int count, StringSplitOptions options), _  A8 t( n" J( ^3 u
( c# x/ V! \* C8 U( X  L
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
4 \5 z' R+ i- G, @5 l/ p. C; p3 ^# p4 w4 O$ A. N$ [
1. public string[] Split(params char[] separator)
; c' f7 U; K2 {: s) }5 M; m
2 A3 R! A  w" ]! _ 程序代码
) O6 j. I# Q0 O; D+ Kstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
7 N) I, S' _5 W3 \string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
, P2 m( v, H$ d1 Q7 V! t: A# U! L- U+ ^2 n
2. public string[] Split(char[] separator, int count)3 O% j' j$ E' V* U
% q- F+ B% O6 ]7 M$ S; J& q
程序代码
7 b$ |: C* Z, Sstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
  f, [! [- Q! k1 D* A" H" }string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
0 P/ i# p) K/ t7 V! P3 c+ T' w6 `( h6 `' L0 A7 a$ s
3. public string[] Split(char[] separator, StringSplitOptions options)
! z4 l' @1 _% ]; a7 o/ b9 P6 j& b8 J
程序代码
" \1 e+ [4 B' u, F, Z$ T: nstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
0 _9 @$ |/ r7 R0 i# Qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% \& b; R7 X; M  {0 u% L& s( P8 E% T6 R- T/ h8 ]- s
4. public string[] Split(string[] separator, StringSplitOptions options)  a* i$ w7 ?; E: b

" Z6 f: }0 @" N# `/ g* Z 程序代码  \: G* X/ b$ _8 W/ \
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" e, ?* n7 a6 @- ystring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: A; A  m$ `4 {7 X* G; i
! x9 [9 h- E& A3 p. P' Q5. public string[] Split(char[] separator, int count, StringSplitOptions options)! ]( [5 m# ]0 I7 j: {. g6 \1 g/ }

  N+ S( t# z# u  F- s! _" s 程序代码
7 V# p& n$ a  Q& }4 P& wstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
$ Q4 e* G3 z+ ^( x) Vstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素+ u4 g8 Z* \8 Y- F  ?, C' E" ]
, ~" {& _3 E. Y
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
3 r6 N4 C5 N1 M7 f" v  l* T6 x% l- {
# Y; U4 Q2 a9 l5 ^代码
8 C/ v* R5 B! ?1 o6 @/ I2 j+ jstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 M+ y; y  l5 ^7 Z7 G  |  Xstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-15 16:03 , Processed in 6.064065 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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