晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
0 s+ S9 }6 I5 i4 \* P
1 J, y: P/ z5 \$ j  S读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码4 [( O/ x: }, \: ~0 u

3 q$ M5 ~; Y& A4 h1 F8 |对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
" }+ `, _+ K" Dhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看6 b0 c% D; ?4 I! r- E
http://www.itwis.com/html/net/c/20100506/8234.html
, C# w, n: \1 {% u: `: o5 @
6 C7 K2 h/ p4 ~7 U. j程序代码2 q) C9 J( g3 C# b* l$ J" F
1) public string[] Split(params char[] separator). a0 C! A0 U3 j  b# W* U
2) public string[] Split(char[] separator, int count)
3 {8 a1 S0 X1 A1 D' W5 `1 n5 e/ C3) public string[] Split(char[] separator, StringSplitOptions options)
7 ?% A2 h9 E6 R; _/ G; I; |4) public string[] Split(string[] separator, StringSplitOptions options)  t9 [4 k) X! @- {  N7 O
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
, t3 c! _; ~; M( V% x# b6) public string[] Split(string[] separator, int count, StringSplitOptions options)
& d5 T& G4 t% C/ u: d9 ~8 t2 p# _5 @3 \  V  }' `2 z
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):% S! z. p1 a6 g# }
& `- p& g' Z! w' b
1. public string[] Split(params char[] separator)7 a0 F; I8 d7 b& N2 |0 f2 u1 D8 Q0 H

3 j% Y0 r0 c6 f9 u% V 程序代码
# a8 R1 x- J6 Y' bstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}( n1 L8 W3 F& ^3 q2 G1 p
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}7 _" c( z5 M6 {+ c, h$ E
" ~* O- l) q" }4 ?5 I
2. public string[] Split(char[] separator, int count)* c$ Y$ @. B7 b; l' Q$ c

: X! ^& Y* h8 g- |7 W6 y( i' ^ 程序代码, ~7 N9 e* k! H" U. |! q! L
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}6 o2 j, w9 ~# q% C$ G0 k6 p
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
& P) y5 V$ g# h+ j0 f! N8 D3 b# y% O2 W; u1 L4 M( |
3. public string[] Split(char[] separator, StringSplitOptions options)
8 D) a; \! i& w' I& D5 w$ G. B; K! }; X( J" b( C' Y1 {* M
程序代码
& y3 G% n! N; P$ n$ `1 Q0 q, a# ^string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; {  N. Y1 e  t5 Q& o) E8 n" m
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
2 A9 f6 z! |# J7 {# }3 v1 o  A% g5 g1 V% n* _+ ]
4. public string[] Split(string[] separator, StringSplitOptions options). T' F  E$ t* E5 `5 h; f
& j6 t2 n' t; d$ E. J
程序代码
0 f$ ?3 w4 Y7 b4 Jstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
6 J1 k- [$ a0 ^- m2 Q0 Wstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 z8 x  K# O3 M# D, @

' R# d  `9 n  A5 H5. public string[] Split(char[] separator, int count, StringSplitOptions options)
& e4 x: ?$ S7 e% v% x7 }- Q
6 c! W' h1 ]- Z 程序代码, ^  g. f% |4 C2 Z: g) @$ y
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素# }) M1 ^/ `6 [4 m! S
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素$ b+ E. Z  t; b4 L, Z% u
0 L! g% x3 j( h
6. public string[] Split(string[] separator, int count, StringSplitOptions options). ]5 C/ A9 f$ L9 A. Q

4 e% v- P* D5 H; E, y代码% d! j- l! \. f  N/ H+ a- W- ~
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素. u, v0 x* U! D. a: }9 D9 ?& J
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-15 16:28 , Processed in 6.074806 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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