晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
9 h+ ^3 m3 L, C" r% e) M# Y- U# Q5 i5 [! I* ]9 L
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
  N& B& Z! a9 |- [/ q3 ^4 S$ R
9 M+ a& W+ O; E4 P对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别# l/ |- Q' z+ a! L
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看) p; {- Z1 \; M# G& B7 R+ H
http://www.itwis.com/html/net/c/20100506/8234.html; E' `( h: b6 u1 k0 G
8 M0 E' L, @, u3 c/ k# ?/ R' T
程序代码* i5 r3 S! b0 Y6 ~8 ?; s" O
1) public string[] Split(params char[] separator)
/ G* E; }1 J: G2) public string[] Split(char[] separator, int count)5 L$ s  L% e# m; F7 K% |
3) public string[] Split(char[] separator, StringSplitOptions options)5 v* h  l$ @# {) N' F1 h
4) public string[] Split(string[] separator, StringSplitOptions options)" W+ q3 Q4 W3 Z9 o6 V3 l
5) public string[] Split(char[] separator, int count, StringSplitOptions options), K) n3 ]; A/ r# u' I
6) public string[] Split(string[] separator, int count, StringSplitOptions options): {  V: }1 P, p/ L$ e
/ }5 m! Y, s9 }1 L5 z# Z
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
% Q, a0 i# V  V8 L+ b$ p
6 u5 j" y1 i. z1 }! q4 [: R1. public string[] Split(params char[] separator)
5 M. o/ g$ F% Q
, x8 @" \! j+ U 程序代码
4 b; C" g# y# `1 p6 {string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
( j+ a  ?3 L0 d, v$ wstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}% k4 H3 H1 C4 e% h$ q

  O* A; G; X! G& N8 j# b5 X* o& P0 L3 K2. public string[] Split(char[] separator, int count)' l5 `9 j9 K: L  e$ q

6 z' r1 Z0 e( z, m" U# u 程序代码
6 G8 x" |, i9 @  t0 }string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}% _/ q2 g  k* b
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}2 [3 r% v4 b' L( M/ t' F" U

% V' n- ~$ Y( V7 b' e3. public string[] Split(char[] separator, StringSplitOptions options)- m5 S/ M  J6 U' h; Q4 U: i
; [: s) }/ j3 }: P2 R4 j* V
程序代码% A( W3 g& H  O" N! @5 I
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素9 A# M- [( k& d  K+ g& b0 V+ l
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素% z; X& H& h2 E, M3 `2 u7 I' S
* _5 ?- L# x4 x' C) D' U, V
4. public string[] Split(string[] separator, StringSplitOptions options)6 D, g4 k3 Z$ t! j

; o1 @$ z" l8 I 程序代码1 u& z  i% a& T+ b6 ?
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
! T/ V0 ?4 J7 l1 Ustring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
- R0 {8 y& n8 J. x, H9 E
+ c, Q0 N' K0 c9 n7 o& ~$ p5. public string[] Split(char[] separator, int count, StringSplitOptions options)7 _/ n! k6 S/ P" t0 _1 r

7 Q7 I# B  e7 V7 K+ `& r- T1 B# a1 J" m 程序代码- v+ L: m: ^, |& i
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素0 \* E6 _* o; Q* _" X: h2 Z
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: |' s6 Q+ X3 P2 g" b( t! R
. C( K* j. P$ d6. public string[] Split(string[] separator, int count, StringSplitOptions options)
/ w- d# X" n; }( ?! e+ `; V, ]( E* ]5 N8 P2 x7 y
代码# s2 k0 g3 D% s
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素6 E# m4 }& Q$ |& r4 T/ i9 x
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-27 09:32 , Processed in 6.071877 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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