晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件; A$ g* E' h3 l0 W2 L
, f7 H7 J! [8 m9 T# y
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
( b. b- W. }* N7 o" N) R4 R
" D! S8 ?# P" t对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
% ~; o1 F. f* g, b; Bhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看, s7 }/ c4 B/ c( L
http://www.itwis.com/html/net/c/20100506/8234.html" U* @, }' R1 U4 ]

* X/ ?/ W% q2 j: U% \; x6 H程序代码
" i" F" ?% e3 r% C  H4 s1) public string[] Split(params char[] separator)9 O9 z3 a$ l$ q3 ?' C4 `& v
2) public string[] Split(char[] separator, int count)# N( ], j, f3 p. y8 {( A
3) public string[] Split(char[] separator, StringSplitOptions options)
/ V: o" z9 B) j3 y4 x7 {4) public string[] Split(string[] separator, StringSplitOptions options)
0 C: n* t, J8 N8 m6 {6 {) y6 D5) public string[] Split(char[] separator, int count, StringSplitOptions options)! K! }9 M1 c& y8 Y7 ~( m
6) public string[] Split(string[] separator, int count, StringSplitOptions options), ~, Q5 G' l& y& H
, Q% k0 b0 [' e1 I
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
, a4 V# B0 z; P, m3 m# g7 M1 p4 D) }( M1 Q; K  k
1. public string[] Split(params char[] separator)5 R8 |, q  ]* w7 `; ?9 ~7 I

; ^+ J$ j( e3 M. W- q 程序代码% u: V' ^1 M5 Y1 p
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
1 C8 k! n: D0 T. J0 s: p7 r! b: Nstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
: J% G6 d% X9 I, D- `
! |; v5 A; z% ]0 E& \2. public string[] Split(char[] separator, int count)
! }/ q; [5 W5 M, j9 P) H
8 u5 R( b9 K$ D 程序代码
2 h/ o* T3 @! e5 c4 s7 istring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
& ?, J3 d* y5 B3 _6 C( Pstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
8 c3 }# ?5 K7 g
# a. n) G9 K1 x" `, y3. public string[] Split(char[] separator, StringSplitOptions options)
; k" _4 Z- g4 |, q9 D# s5 K0 R9 g, C" T6 c
程序代码
# @. J, X' [$ o3 Z% P, Q+ H' Nstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素' C5 k. g- K+ e
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
! V, H0 q, v% x3 n" V+ S" A+ f6 U0 a+ u. w; w* A% e- _7 ]& h# N2 |
4. public string[] Split(string[] separator, StringSplitOptions options)) N4 d% |4 n$ Y
9 [' r6 M* i: P; e/ y. _/ H
程序代码
- l% z) _& o7 h" j( P# ?4 s+ pstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素8 c; h" f/ }6 k( y; x$ {7 w$ A; z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
9 ]# G, w. j6 n/ j2 A* ^; ]3 g/ f" T- J! F* ]
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
: t2 k$ P" C* ^5 E4 e  Y: X2 J# I+ |4 f! k
程序代码
# R! \# O. z' g. Pstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 b0 ]9 ]( q7 o& {string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 ]' m9 P% P& ^
( `  S0 c/ }: ~3 a1 X  Y, O6. public string[] Split(string[] separator, int count, StringSplitOptions options)
# Y0 V# T' m$ o+ \4 l, _, G6 u  {) J/ |9 f3 `
代码
7 f  U* m4 a: n2 G. F' hstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! _& p% S; |& q( d  y& z- u& |string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-21 06:07 , Processed in 6.067971 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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