晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
. t; Y2 \, {- T
5 A  d; T- E8 Q  l读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码3 H( J6 M: F3 R* e4 Q6 |, t2 m; v

" K  Z7 f( X: c4 g* B对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别4 C  N& x/ a- o- x
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
1 ^2 L; X* a) y) b  [http://www.itwis.com/html/net/c/20100506/8234.html% @. O8 }$ z0 j5 r5 @, ~
7 r8 w, ^7 _  g
程序代码' c+ b2 N  F( N) Z: _) d
1) public string[] Split(params char[] separator)+ I2 ~! ~2 ?$ L
2) public string[] Split(char[] separator, int count)
2 ~$ Y$ d9 ], Z+ \3) public string[] Split(char[] separator, StringSplitOptions options)" q3 y$ F5 C. t0 l- m: U- R4 T
4) public string[] Split(string[] separator, StringSplitOptions options)
. X* n! b" \( c0 G9 v0 S5) public string[] Split(char[] separator, int count, StringSplitOptions options)( H9 n# b& ?7 j# j1 q" J0 c' w- I
6) public string[] Split(string[] separator, int count, StringSplitOptions options)3 d6 ^& k( @# L& ?

0 |# ^3 S/ n4 C' S' K: ~下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
4 A: [& Y8 N! e: f. _6 H+ ]/ n+ i5 Q# m
1. public string[] Split(params char[] separator)2 W3 z2 ?0 D# y# x6 L
2 p8 \3 }; b* p* Z( ?% ]
程序代码. W8 G: |7 t# D% V. b9 B
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
; B- G- v( k2 V% a7 D6 `; estring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}- o4 ?, c9 e& k. W. @) n& Q6 g) e# p5 c2 Y

7 j4 z9 r0 r* F) K! I2. public string[] Split(char[] separator, int count)
9 J$ |/ u. h7 f& x  n6 u3 E' W- J7 i  P4 B* H2 q) l
程序代码
9 c. n8 G% y2 }: X' Y/ k! @+ ^string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
2 f. {0 S! G4 v$ E/ \7 vstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}0 z7 D; L) }# Q+ ?, d# ]* t
! P1 K2 j4 F$ [$ p
3. public string[] Split(char[] separator, StringSplitOptions options)/ S& N5 k% u% h" e/ m

. o  i7 G+ w1 @$ k# Z& g1 L 程序代码
* N$ m# n2 ~. {+ W8 G' s0 T, kstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
7 e7 o/ c  P/ r' Lstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
$ f" s5 D5 x( I( ^
  E/ A! j- J" }; `( y4. public string[] Split(string[] separator, StringSplitOptions options)( Q$ p9 `3 R7 F. _
$ Y8 K6 X. M* P; w# C2 i
程序代码8 m* i! Q- O8 m3 |/ Y
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" F, L% V( g0 ]* J9 ostring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素' Y* q8 z) I" L
9 b$ a1 A2 b5 v' r' ^
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
" d* a6 k( @/ Q. o1 h1 |* o: Q
* `0 `: {- f8 D  n" t' ~/ X; |2 k  b( z 程序代码
  h9 b3 h; D4 [* ~string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素- X4 m( K+ d" J1 Q3 U
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
5 ?; H1 D+ l& X2 e
* C; `) M  e1 C; {2 N5 R# h& l6. public string[] Split(string[] separator, int count, StringSplitOptions options)! o* W0 E! R) d9 v9 J  ^+ L
* Y* I( c" ^9 U# I0 O# v; Y& {
代码
. H( z/ R$ _4 M8 P+ u! \0 P1 Estring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
+ N4 \' @" G# |- ^string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-8 09:51 , Processed in 6.067971 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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