晨鸟科技

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

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

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

4 U$ a- t9 H1 o0 P读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码$ h8 Y1 f: Z% k& M+ j3 L
7 s1 M8 k  M- w* V5 V* m4 h) Q' }5 R# z
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别  o0 [5 a. ^$ {" P9 d/ s
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
: u" t* \: w4 ~8 V  u) z5 P5 dhttp://www.itwis.com/html/net/c/20100506/8234.html
* L9 h$ ?  x2 A) n9 v& t0 \$ V
6 c. y2 W; a7 c. s6 r3 [7 y5 w# F% W程序代码
- @$ W' x6 Z' Z- s: J- C7 p1) public string[] Split(params char[] separator)
- r( t- L9 a- `& X2) public string[] Split(char[] separator, int count)
0 v) y" h2 ^: i3) public string[] Split(char[] separator, StringSplitOptions options)5 @' z$ U3 |  X$ K4 e* D
4) public string[] Split(string[] separator, StringSplitOptions options)5 ~# A* ?, l) s" G5 m% W6 r
5) public string[] Split(char[] separator, int count, StringSplitOptions options)! N# o6 A& C2 M  p/ |' {* F
6) public string[] Split(string[] separator, int count, StringSplitOptions options)1 \( o2 f1 X7 B  H

! {" [/ {" {0 a* i9 F- [3 A2 m下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):' V+ m" X7 v3 n0 ^+ x1 G

* {0 W! ]6 t+ o7 W+ k. B3 N1. public string[] Split(params char[] separator)$ U- ?" }4 `! ^/ g( g+ g

5 b4 M, @+ j" }; @% P3 l# S& h9 ` 程序代码: F( d/ y4 O1 B2 k
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}4 _# E3 L: o5 K8 h0 f
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}- \6 k/ R2 l  F$ D' y

% r4 P& T# t2 `: U- o% e, f* R2. public string[] Split(char[] separator, int count). o+ P! G7 @: [5 K' h7 r

' V$ }! a- u/ l  h1 D0 N9 a$ ? 程序代码
3 p. n5 s  K( |2 wstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
" T4 ]# s5 C! ?string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
- W/ S& U0 F2 }6 }  K* }, C
$ @* ~7 s$ B) b$ S+ n3 R3. public string[] Split(char[] separator, StringSplitOptions options)4 x, I; S8 o4 v, P4 {

" Y) N8 ^- E8 N  t9 T# \ 程序代码
3 a/ o# R- P; D- ?7 r! }) w% |$ s' pstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
6 G. Q) `, Y  ?8 `6 x2 l8 X4 v" jstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 \7 I9 [- Z3 N7 G
- S  k0 C6 R. ^* m& e" ~* N! V
4. public string[] Split(string[] separator, StringSplitOptions options)
4 l0 H& L7 l  t  Z. @3 o5 N! A- r% u) L+ F! z2 W2 w
程序代码3 `. z$ Y1 P+ Q/ f
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
1 i7 o8 V9 L7 O' zstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% t: x8 e/ T( |! I5 ?4 E0 l4 F% S  j& J: L# J* e% X
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
4 O. n$ O  K( x' S$ x( P* I- g- S% s. A( `% H/ o4 Y
程序代码
' q* n" O. m( m9 t( I( j, rstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
5 X9 A! W0 Y$ Wstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
4 N8 R* A7 v" o9 U& M  s# v$ Q# Q
6. public string[] Split(string[] separator, int count, StringSplitOptions options)9 R7 G& f) r) S! l  `7 w" f7 e
" R+ U& X1 ~! E4 a+ r2 F/ T
代码4 {' o$ {  M& D& T
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素# C+ c9 V0 o! o' e/ \/ T( w' O/ i( I
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-6 05:23 , Processed in 6.065662 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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