晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件$ b  Q1 y2 l- m( y0 G; q3 I

; H( a' G7 X) B/ q0 j. `* {读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
5 \. m/ @' w* i3 u/ v4 Y! k# l
% s% q& k. ^1 ?) C/ n: }8 ?2 K对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别" }% b# N4 M$ ?1 h+ X* ^5 }( h* ^; o1 i
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看6 A) C& r; C. |" |- @$ P
http://www.itwis.com/html/net/c/20100506/8234.html
8 J1 ^% i0 f, ~$ w% g9 L' ^
  a( @* b7 p! ^1 P' ~& t+ h& w程序代码
6 `+ R: r8 t1 H$ c$ y) t9 o1) public string[] Split(params char[] separator)
/ x( _: N! f5 W2 G2) public string[] Split(char[] separator, int count)  w3 _$ T; D1 N% ^( D
3) public string[] Split(char[] separator, StringSplitOptions options)$ s8 d& y1 T$ G5 N- e5 }) e& ~; R8 n
4) public string[] Split(string[] separator, StringSplitOptions options)6 Q5 S9 I# G( B& ]
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
% d1 ~% ?) p* U1 f. G0 m9 q0 ^6) public string[] Split(string[] separator, int count, StringSplitOptions options)  [- R/ F+ ~; G' P+ A5 S9 c
" _" e& b# K! Y3 D! b) ~$ I
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):( d6 B. y' D. c! m* ~9 F
0 p% y* _  e+ {% ^& \
1. public string[] Split(params char[] separator)
. Q6 \; K1 _4 e! n$ C- p0 ~# j; [" J5 P" O% M
程序代码
% ]9 a  f2 p6 ?4 t* fstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}1 z; O3 P& W2 H
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
- ~5 ?0 P7 b' ]- @. m* O* B# T) k( o8 W( {
2. public string[] Split(char[] separator, int count)
# `: K2 f% {  E  h$ B) i) K4 l3 r: t) H0 {. i, i/ z$ c
程序代码
2 b! t6 _) ^7 K0 J  O: ^% cstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
2 }/ z  @' h' Dstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}0 i+ N8 s$ M' t. I* h; {

0 H) y4 n" S6 J6 c* U( n3. public string[] Split(char[] separator, StringSplitOptions options)
8 M  A6 i( [. \! J! w3 [/ p& T& o2 e, v" W
程序代码
& O2 \7 f5 N9 @string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
( J- T/ P6 c" Z' I) i, k4 d) istring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
9 r- O  {! d: M6 L9 m7 a
; I9 R# ^  K& h. N4. public string[] Split(string[] separator, StringSplitOptions options)- H7 h  m' s4 o# K+ H2 F

# z* g" N  q8 I; Q 程序代码. |% U1 `7 Q; C
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# j# f( j$ d6 s. H& D) a% b
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素! W$ z  n8 s" y% h* B( X
2 o/ y) f- j6 a/ j
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
! h5 ]  z, D# }- L4 N
( u! G( h3 }6 c- y, K1 D; ?; O4 b 程序代码6 u/ w8 D' T$ E1 w% t$ x
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
' ~4 `1 a- n" Q. I7 s9 X7 Tstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素0 p& c, j, ?2 i; \4 {* |1 j

7 n) P, ~" v1 N9 _6. public string[] Split(string[] separator, int count, StringSplitOptions options)* Z! g; `3 j$ O" M* P1 M

' R8 n& z& p8 g4 O- Z: {" l! L代码* @! b9 I& e# r  V& i3 [4 r
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
0 F& C, ?3 I7 ?; h( o& vstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-28 04:58 , Processed in 6.067616 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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