晨鸟科技
标题:
升级程序开发——读Web.config、执行Sql脚本
[打印本页]
作者:
Star
时间:
2011-2-18 17:28
标题:
升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
u& `% v; Y2 P2 y# l( h- x8 h
4 |: ~' E& R4 T5 H9 @
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
% P" ?! S8 P. q0 S. {1 u
z/ q- a1 W4 K
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者:
Star
时间:
2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
# d- ?- C& f' z( @5 A* B
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者:
Star
时间:
2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
* v6 }! R) v1 @* g6 k- k
http://www.itwis.com/html/net/c/20100506/8234.html
& P5 _1 _; x2 o" Y: p+ l
8 h1 ?9 k1 M' E. ]/ @
程序代码
1 o8 r0 W \6 M; u( U3 [
1) public string[] Split(params char[] separator)
5 K; R# L" n1 |" F& V6 n
2) public string[] Split(char[] separator, int count)
4 C4 O4 G4 n4 A/ _
3) public string[] Split(char[] separator, StringSplitOptions options)
5 {* ^% V' X3 X+ P. O
4) public string[] Split(string[] separator, StringSplitOptions options)
3 t' F( h2 j4 |. |' G; ]
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
. O5 k* |! u! r9 Z* J7 ]
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
9 P) d2 |5 R& [2 C6 G9 X
( i' u+ i8 H3 R4 h; Y3 K
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
# [4 s/ e: P. m$ a
7 b& u9 e. X& I+ e' Q+ r. v7 w2 @
1. public string[] Split(params char[] separator)
& o' ~, A, i2 @
! G5 F |3 y5 o8 C7 |0 |# b+ f
程序代码
+ h: R' c2 ?" u
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
# [: H6 p' K- Q$ j2 N8 m
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
( d3 J7 v! t4 B; A
" [6 f5 L5 c3 C7 f+ A% f% X- O
2. public string[] Split(char[] separator, int count)
* t/ T( \ M! S6 Z. _) @3 T7 k( M
+ c# X& @2 E; @& ?1 r- \& d! m
程序代码
! L( M: j! D- s7 @! b
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
- E% L4 B K: w5 e1 J( S, S8 S
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
# @1 n4 x7 U7 F; q( v8 a8 n# ^# i
3 y Q1 b' [/ ~; F! N4 L. O/ u7 F K
3. public string[] Split(char[] separator, StringSplitOptions options)
4 s4 {! i- a* a3 H8 T
& _* H% W( Q6 N' s$ D+ W6 Z2 @
程序代码
- ]/ d7 N0 f, @% w! K$ `' Y; b3 u7 t
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
/ V! Y% O7 L7 o+ d1 L6 @% e
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 E+ [% b# X) O7 s) j: i3 W' g
% j- m$ C r1 ?: l% q) L h2 G4 k% E
4. public string[] Split(string[] separator, StringSplitOptions options)
9 B5 Z4 B+ I. d4 m' Z4 y
~" z# {! m. _; d1 ^
程序代码
& z, z; h2 e$ ]* c
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
0 m8 k; f4 ?8 {4 g6 ~2 n( V
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' V3 c3 o0 E% J) X/ v2 [
# j2 z0 }5 A; k C% ~% O; T# \" ?
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
" n4 w& ~7 V/ d0 ^3 S" A
& N1 q( V9 k* }4 a6 {8 i! K- T
程序代码
) S1 U7 e4 k2 I7 w% j+ }
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
1 K& o3 {8 C' g( N4 q# X
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
& n R H# i& L2 V( _% i
/ I9 ?# ]8 j& w
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
( g0 J9 }% ^# p* q% {* O
" I7 @7 C0 P6 i' Y: ]
代码
$ {# g8 c" Z2 |3 q( A1 P7 I2 H
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
0 [* T3 H& y/ i3 J; B7 x, J t
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
欢迎光临 晨鸟科技 (http://www.chenniao.com/cprofessor/)
Powered by Discuz! X3.2