晨鸟科技

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

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

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

$ \5 w) G5 I: o$ w" I/ p+ Q读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码+ v. M7 Q' m( c6 g; B' s

/ I+ C% ?, Z/ n- a9 Q对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别; V6 H# }  U! l+ y6 S+ h
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看& Z7 {% o3 t5 k+ Z% v
http://www.itwis.com/html/net/c/20100506/8234.html  b8 }/ o! o" p- h+ G
: M/ S, b  `# m* q
程序代码9 M5 `4 b9 F* f  C7 \. N+ r& N+ x  {
1) public string[] Split(params char[] separator)
- l# d8 q6 i3 b2) public string[] Split(char[] separator, int count)# U" H" ]( V' G: M
3) public string[] Split(char[] separator, StringSplitOptions options)
7 F, G3 \0 O* N9 I! M! `% P! D4) public string[] Split(string[] separator, StringSplitOptions options)
9 {; g% E( G' D5) public string[] Split(char[] separator, int count, StringSplitOptions options)
, I. f# `7 |1 R( Q; j% |6) public string[] Split(string[] separator, int count, StringSplitOptions options)
/ s, O/ [7 u0 K  `. s& R! D% |9 d" O& }, y4 T
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
3 u. ~7 S. O% C! E  N# z7 j9 r
" g( V8 x$ Y* M5 w4 T+ c1. public string[] Split(params char[] separator)  P+ W9 s5 d9 j2 @6 a
% Y; Y9 K& D9 H. h" \
程序代码
9 M' F, W; U9 H, u  i% [6 B+ e. mstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 Z. P0 a  W4 g, @4 P6 S
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
, _, R, d+ W0 H
! p  }! T% K  x. B) Q; K1 H: d( A2. public string[] Split(char[] separator, int count)6 s* r3 L, o& B* O' [) y" ]3 T

' u% P4 c6 ?( A# L0 X/ w( ^8 }7 R 程序代码
* z2 G3 ~6 i; U5 W/ R9 [  X1 bstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}+ S8 f1 Z" b. s# |
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
9 ]# ^* B; p, G9 D% C
# p: ~5 t  m% n) K3. public string[] Split(char[] separator, StringSplitOptions options)& e- C% b' ^4 H+ [

9 b2 X6 x! A/ }# q 程序代码
2 h' a9 p' k* C5 P' Q$ Nstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
  V1 }- A# J7 g' X3 o: d; ~string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素  M2 F2 W* @5 N1 @0 ~8 p5 V
8 j% L/ t  Z% s) s3 w
4. public string[] Split(string[] separator, StringSplitOptions options): f5 f9 A5 n2 C: e3 g
+ \& b1 e* T( w7 V2 H- P/ F8 u
程序代码
( f+ k+ {6 l" ~+ f' kstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素( a$ X: Y, Z& i! N
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ m/ \; P9 K6 ^, \9 Y- y" F
9 w. D- [& U( y4 q5. public string[] Split(char[] separator, int count, StringSplitOptions options)' e7 x* N  ^" A$ X$ L$ g
% \  b+ z2 j: N  d3 @2 K" U4 x
程序代码# O) G* q5 s4 W- s2 I3 [" v
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( w0 z8 F( g: _# a) F; U3 e
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素6 }/ A6 h  h4 D- b

) s5 l4 J& c/ e5 C5 ~6. public string[] Split(string[] separator, int count, StringSplitOptions options)
+ ~* [7 x, d: h9 {3 J+ H1 c6 \( b9 W! X. x7 f
代码. P4 e8 u7 J8 X* c/ }6 g
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( T4 w, V! T4 s$ A# A& B  _string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-14 06:38 , Processed in 6.076760 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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