晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
) }" @$ ?, N, j8 }5 K9 K
; F# S% v' H% N9 C读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
; {1 V& `) |  j6 |- r4 Z6 G& I
2 b4 u0 Z# h; \1 _9 X7 \对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别4 T7 l' T7 _: t- p- s' D
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看+ f$ l( u1 e$ B) S9 z5 h1 {# }3 W* B% R
http://www.itwis.com/html/net/c/20100506/8234.html( n1 H- N, o- i4 o: }6 I# ~9 e( Q0 ~
8 u& k/ _* f- w  O5 A, h
程序代码
$ \9 `8 h) G" X( m: I' X1) public string[] Split(params char[] separator)7 A4 N. ?- D! Y/ o5 L1 r1 D
2) public string[] Split(char[] separator, int count)
; X- k3 K. s, g3) public string[] Split(char[] separator, StringSplitOptions options)
& l. @! y+ Z0 t4) public string[] Split(string[] separator, StringSplitOptions options)
: `2 v; g# W3 e  l5) public string[] Split(char[] separator, int count, StringSplitOptions options)
7 z9 T9 @! U  g5 x4 }6) public string[] Split(string[] separator, int count, StringSplitOptions options)
- }2 |7 _% O8 _3 K( v) f, r1 w5 e. e. F
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):4 A! b9 _- B7 q
* O( C3 D0 `* v7 ~
1. public string[] Split(params char[] separator): l2 N+ @8 _( P. y3 f1 P, d

7 t$ [# X6 C# { 程序代码  W- z3 D8 w( t7 K$ R# |1 |  Z
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}/ ~  J' o5 K. o; o. C! Y
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}3 }! U/ h; Y; X1 V1 Y( w8 y
" q0 }, d, g& l! d# x
2. public string[] Split(char[] separator, int count)% a: i" T# v# _( r( r4 {1 Z5 Z9 ^
8 A! \5 k) V4 V$ p1 o. i& M
程序代码5 t& Z& ?8 j5 D" ~# b! W7 F6 u
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}/ |, d. O9 b8 t3 ~& D$ h' g
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
2 U8 @# l* @- ]) a, N5 T% ~- T# ]
/ W2 q" r" e' s1 G3. public string[] Split(char[] separator, StringSplitOptions options)
% ]* ?/ B& _8 q, A$ i& M: X' I4 e% Z  W5 c, C' p$ ~* t
程序代码4 A( y" w( Q$ @; q: j1 v0 r- v
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
2 ]4 [0 b- m. K& |. j% rstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素6 q1 U! O3 o7 z) V6 Q0 {9 a0 r+ y

4 L! H  s% Z. x/ Q8 P4. public string[] Split(string[] separator, StringSplitOptions options)
1 J) B1 m& A+ B7 J/ t2 m$ f1 m) {! y6 s! m6 }2 f
程序代码
" f' w8 ~. r, y; T0 D) O* zstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
3 q. e+ _; j# m- \2 T7 o+ ]string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# q2 a5 M8 ]6 i( b  s
4 _* A+ ?% I0 E" A# m
5. public string[] Split(char[] separator, int count, StringSplitOptions options)0 Q. O  q, c1 O3 _* j% p: e! a, f

& P# R+ ^% M8 O% K 程序代码
6 y9 \2 |0 h+ C6 X7 \string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素" m) z3 u2 @0 ]
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
) ~" H9 q0 S& d% v( ?* R% ]( O4 E) `9 [8 O
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
& ?6 {4 L+ i; Z1 x& k( T! B! Y% j( W* ^2 E' m: G. _3 w( [8 B
代码
  U) Z7 d2 w" [5 D& s; _string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素7 D0 a' k; H0 V( |7 ~# w* w" [
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-21 12:20 , Processed in 6.067616 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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