晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
, e+ o5 K4 @9 u( i9 T4 D8 D, @+ N" l5 O2 Y* `
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
0 N* |0 `! q7 f& F
0 g0 ~0 n4 J7 G  ]1 G) M# C3 K+ v. f/ G对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别8 o3 G, x- L$ V7 f+ l* B
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看4 m+ V, O, J  f1 Y2 y7 z% @
http://www.itwis.com/html/net/c/20100506/8234.html8 @5 h- c( v, p! ~! f- k

- i! p7 J$ U' @3 T4 X& O% t程序代码
( C$ N7 y+ w$ X1 B1) public string[] Split(params char[] separator)* U' l# b6 \  e
2) public string[] Split(char[] separator, int count)* g4 [- l1 H: i0 t$ |. l
3) public string[] Split(char[] separator, StringSplitOptions options)
7 Q, d& Z9 Z4 y; n+ }# O4) public string[] Split(string[] separator, StringSplitOptions options)/ O( W  l' ?! Z
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
# o+ p! d. [+ F) `! f6) public string[] Split(string[] separator, int count, StringSplitOptions options)3 Z6 ~: P) Q( T

; q, b6 c  I! J4 h8 }下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
5 A+ e/ g# c  i4 f! X5 |6 ~5 `7 u  M
1. public string[] Split(params char[] separator)3 h, L& w% W1 P
7 P4 b' f  N  g; `2 u
程序代码4 T" j& J/ m; X& g1 r3 Z! o
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
" P  @7 |  {; {' S/ ~& {string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}) F/ D* m- T: h

: B: V2 u! p% F' i2. public string[] Split(char[] separator, int count)) f$ a8 r+ M4 Z1 `$ ~5 G& M
2 T6 D4 j8 }$ s! q( R1 S6 g3 u
程序代码
$ i1 b. ?. ^- J+ R3 t* E/ `string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}6 J' Q; S& l! e9 w' \4 e+ _$ ~7 i
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
& d% p- Q( K3 n  G, ?$ T: @6 Y. H! A1 Y1 @) g. V% {! I
3. public string[] Split(char[] separator, StringSplitOptions options)" P* f; \) c5 T/ v

$ Z3 Q; t0 M! w2 Y 程序代码
" x" o& }: p5 l1 ^9 X: ]' tstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
7 s: ?/ d& P8 R' Gstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
; U# a# `9 B: y1 h& ?# J9 U# D. S' k4 {0 M5 L; g
4. public string[] Split(string[] separator, StringSplitOptions options)
( z  ~% j4 S$ R, S  o6 i# D. D  ~5 b# I* q' S
程序代码' m4 A4 A  u( D* X' U$ `% @
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素8 o( ^9 s/ L5 M5 ^4 D( Z! g' R6 J
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 Z2 e# V+ ^/ C4 x, q: f: T( v% v3 S: I. ?/ B$ x3 M
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
  C* h9 d; B4 `' y1 L% v/ C& e$ I% G6 Q0 s0 C; Q; \
程序代码
+ I) K/ D3 K8 U/ V6 F/ C% Istring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
, @' c2 F) h1 s3 estring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素+ j% E9 ~$ |* j0 ?6 j& e  J

0 o2 S* E5 }0 O. {3 [7 d  `- j6. public string[] Split(string[] separator, int count, StringSplitOptions options)/ ]& J& H- X$ m$ }2 m

! y4 _. q8 W, p+ `" p; c* c$ s; P代码+ E/ Q* a+ h: G- \5 m0 u4 S
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! n! v! g. @0 b. |- C/ S
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-5 09:18 , Processed in 6.080666 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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