晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件' t* b7 k! }) W) P) G0 X0 z; v' a5 K

% F9 a& Y" `2 h1 \; A读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
+ R  F4 o) T9 d1 V. j
7 z- k- p% l% q/ E! G对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别" {. o8 S( T+ @2 B, d. Y
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看2 ]- f9 T" ]0 ]* c! c, D% }
http://www.itwis.com/html/net/c/20100506/8234.html
+ B5 G. T( O9 {2 c  r7 N+ P2 k4 q) C7 I2 P
程序代码! @' P. t: L% H$ \& b$ q+ K0 \
1) public string[] Split(params char[] separator)8 r* p$ Z9 `: x
2) public string[] Split(char[] separator, int count)2 T5 y1 V; [1 w$ e+ {7 W9 k5 J
3) public string[] Split(char[] separator, StringSplitOptions options)+ N# s( _" ~% L, j% x
4) public string[] Split(string[] separator, StringSplitOptions options)) s6 B/ K+ ~- U/ l& R* e
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ i, ~4 _' Z, O6 g6) public string[] Split(string[] separator, int count, StringSplitOptions options)
# E" `: H2 V( ?' e/ Y$ N7 K6 ?& ?
1 U5 G: _% v* B. T下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):. l$ o$ b4 M2 C

% I8 D/ b5 Q" k1. public string[] Split(params char[] separator)) ^" ]3 J; [0 I% ~* g7 j7 ]* F+ P

+ q: Z1 B0 _$ m" W- Y 程序代码4 H/ d8 v3 S4 l0 E8 W5 i# N
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}% p: _/ q" ?: D1 ?9 i+ m
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}  L4 k7 k( f/ d& `: L

% b" _6 D; M  g% r% K: K; T( W: |2. public string[] Split(char[] separator, int count)
" J" l" V$ j' X9 h0 V" K- J+ g3 b7 t" c' \& e0 n
程序代码+ |# h, L2 p6 A+ o0 g% ?  K' g
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
# }8 n" g* [2 W/ @. c' @1 X, kstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
/ v7 P- \1 y# _6 ]) l2 \" V
6 B; K; g0 |) v! g% ]3. public string[] Split(char[] separator, StringSplitOptions options)0 z) G4 i' u2 u) \- \, l% P3 f1 s

( O. m/ @( v6 ]4 N  c9 N9 g 程序代码
& H& R* l0 W4 V' Y# wstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
# t6 l! K3 }! X$ P& V' j# ^4 ustring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, C; H3 ^8 P- D' P) z

' z3 l( @1 F! C$ k4. public string[] Split(string[] separator, StringSplitOptions options)* G8 {( M0 ~2 Z) }# O

" W' }* i3 ^5 a/ H8 ~8 F8 A 程序代码* P' t  [5 l& O
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
) G& V8 x7 m: k) e+ Y1 wstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 P9 E1 E- k. G5 b9 Z1 F" Q1 _
  f; G; o* C/ b$ k( M+ b0 E1 `
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
. `) O  Y/ D6 b, v  C
: t4 B; f6 f" z# h 程序代码
# s4 l: J1 ^+ W/ O% i% {/ F4 [string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 X6 Z$ x/ K# B# l' M, G- vstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素' h9 d/ |1 R) L$ D

7 y9 P, w1 n7 f3 m0 Z6. public string[] Split(string[] separator, int count, StringSplitOptions options)0 v! r. \5 t" k* i/ A" J9 |7 O3 C

" P4 i0 v$ p4 k; y代码
2 M& h9 t  g5 l. _+ [8 dstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素% ]9 F8 [) b5 o9 S% h
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-25 21:52 , Processed in 6.065663 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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