晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
8 U- X& U; m3 j* U( ?. D; \+ B0 r
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码5 @0 n' T! `+ j, ]

9 p( S7 P# k* }: I* N' ~+ l对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
- m! d# G8 T- V$ Ihttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
# C  K9 Z" B! i. p' Q4 g' F+ Uhttp://www.itwis.com/html/net/c/20100506/8234.html
2 d5 d: i: M9 Z# W; ~& F0 R4 X& E* n+ o- e1 y- Z( Y& `
程序代码
& l2 U6 y8 h, l1) public string[] Split(params char[] separator)
# y4 [. r$ Y7 i* `2) public string[] Split(char[] separator, int count)
3 t" ?% s* o; W) {. D' B3) public string[] Split(char[] separator, StringSplitOptions options)( Q; W# [; d8 M. }5 c% }* i
4) public string[] Split(string[] separator, StringSplitOptions options)
0 Q$ [. b- f+ K! Y7 E) k5) public string[] Split(char[] separator, int count, StringSplitOptions options)
( w: h; e+ X; N+ [' M6) public string[] Split(string[] separator, int count, StringSplitOptions options)" z3 G* Y1 P  s$ W, I8 x
- A, J6 [$ K$ y+ f5 D
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
9 p$ j2 e) E# m* o/ k# p$ {  t9 ^4 j! @6 M) U4 e0 b
1. public string[] Split(params char[] separator)
* z6 I! j$ _& G
1 A1 G/ _) N$ [( @' ?( C" c, c 程序代码
; N$ V. I' u) L8 _. L0 h: zstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
  x0 a9 W! f% ]* \% }: zstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}: \! }6 R! b4 J
! ?+ |9 `: e3 L) I9 p: v
2. public string[] Split(char[] separator, int count)" r8 X; a( z) D6 i
) {) K+ P0 j4 s# Q# l3 n
程序代码
! }% s/ G3 _# \( M$ L2 @3 F6 _8 U  y* Hstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
6 ?; x9 A2 Z7 q. @# ^# J, astring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
9 v, g% f# E# k1 m& g& r) v: T1 {, r- ~( F* Z6 d
3. public string[] Split(char[] separator, StringSplitOptions options)0 W' f& k5 q$ Y! N  ^  g* b

- I2 k  j3 I4 h3 O4 Y9 V6 B7 x5 | 程序代码
7 x4 R. ]( F% ~# E; Wstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; k- a$ A2 `- f5 e$ z/ M* h' P
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
$ n4 M) G! s" y% l, T: A# R9 m% g2 `% p6 S
4. public string[] Split(string[] separator, StringSplitOptions options)
0 q0 V0 F8 Z1 ]: t# o7 M, @$ u  d
$ h/ ~1 O: ^9 A7 v2 Q: h8 J) J 程序代码
$ ~% |% y: T# I- ^. a) Estring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
- X$ J. d- N2 B- {string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 P- {+ {% l* c! J% E3 h9 n
: ]$ u% N  U8 D* y; i! v/ [; I5. public string[] Split(char[] separator, int count, StringSplitOptions options)$ m' K2 ^5 P+ w8 `$ l  n
+ g* [( i1 A8 G5 L7 z: p
程序代码
# }. o7 N) Q6 O8 i% @string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
2 v8 t& ?6 \, N7 S3 Q& ^string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素8 n$ B) @5 L* f7 N: b6 a# W. ~
  B- ~. s# n/ H* a" L) g  B- S- g
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
+ A  r  z! ~5 f/ E
. B& V! r$ {4 M代码
: ~3 x$ i  K) d6 C' hstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
" p, {2 U7 ]' }* y$ b  K9 X3 bstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-25 17:58 , Processed in 6.064686 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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