晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
. C0 R- D: j, S" a3 m+ J, M; D% |6 a( ~2 x
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
; [. L- b% E( d- o6 T8 |6 }! `$ |" B2 M' X# c
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别. o: e) m) T2 v& j. \' @# ~9 f& Z; w
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
, D7 v2 o& S+ d; J3 {$ ahttp://www.itwis.com/html/net/c/20100506/8234.html
3 A* r& i: w7 S2 V2 L* H4 p
7 K3 c; G9 ]/ p程序代码
6 j0 _; L% [9 ~3 v- g) y1) public string[] Split(params char[] separator)5 M8 |1 |1 F+ d+ D; t- T6 H
2) public string[] Split(char[] separator, int count)( T/ G0 ^( t/ N
3) public string[] Split(char[] separator, StringSplitOptions options)4 P0 o, N" P( H; U  [
4) public string[] Split(string[] separator, StringSplitOptions options)% U7 k& }; P/ ^6 ?2 ?
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
  E5 `$ J% [/ c7 v1 t* D# U  z6) public string[] Split(string[] separator, int count, StringSplitOptions options)
# r8 ~! {7 Y7 \  D# E1 p7 H, N' G+ F1 t( S2 f4 q
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
. k6 u. ?4 D9 ?) Q/ x) n, K7 U# S$ a7 p9 ^, X0 [  d+ y
1. public string[] Split(params char[] separator)3 W$ Z' U- ?! {; r) l. a

$ U7 }3 e3 A+ T# W( f6 c6 d. c, t1 b 程序代码" k9 W& @, x- b& ~! M2 {) W
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
7 r2 y6 K' G7 D# Estring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}- N9 g8 O: |( V& m

0 _( S% S8 U$ ?. ~& n2. public string[] Split(char[] separator, int count)
. G# r/ `' V* @2 [# }4 b8 i2 W
2 f% k9 d/ A% l' w' S, H+ [ 程序代码
& M- B7 [9 @9 E! J# G7 I! f3 Nstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
2 C& U' s' f  }; bstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
9 h+ Y8 V; U9 X- X! I; [/ O# ~" `; \- n" d+ w3 y
3. public string[] Split(char[] separator, StringSplitOptions options)
% V. F: r& G% D# s$ ~- l3 f' k- T+ H+ y6 _3 U; u8 A5 V$ {
程序代码
- ~; I* ]! }1 T$ G/ ]! Kstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
5 E' X- w; F. u5 P) ystring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ A4 v, q4 F* i
8 F! D3 Q8 K( `' k
4. public string[] Split(string[] separator, StringSplitOptions options)2 t! m, @5 p8 e! g) b5 V
. ^+ p. }8 i3 Q: ?2 E
程序代码, Z" V8 X. @7 e( J# n1 n* R
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素' \2 j* r: }" O
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
) `( i5 K) R# z: L" P) @' q; F& |$ @% |5 s& i# e: L
5. public string[] Split(char[] separator, int count, StringSplitOptions options): {. Y0 G% C/ K

  S. A! o% A0 |" z3 Y9 s 程序代码# h) r2 K! b# ]) k/ {
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素) q7 _. k9 ~4 q' S$ a
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' W& \0 S. s9 s7 i: ^3 _
6 r2 C) h* b3 f9 M$ b: [. Y6. public string[] Split(string[] separator, int count, StringSplitOptions options)% H; h6 j- f  L& w: v: K
! F7 H3 @  w/ {: L8 }. u2 R8 c
代码
) s6 V  p6 m# ]$ Ystring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素; E  M( A- ^! P) X1 o8 T8 Y
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-30 13:20 , Processed in 6.071877 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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