晨鸟科技

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

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

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

7 v# ]+ G) E$ R6 a/ H* ~( [0 ~读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码7 [3 Y5 q9 ^' A- v6 g, w
: ~% k* O! W. @6 Y% D! n
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
* u1 B/ v0 k- @http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
; K0 J/ F& E. i& V& g- ahttp://www.itwis.com/html/net/c/20100506/8234.html$ f/ L6 K9 Y$ c4 s/ y8 a
) ^! v7 M9 @8 C, Q* S
程序代码
: {5 t( q) g2 s1) public string[] Split(params char[] separator)
7 L0 ]& y* \% X+ ~2) public string[] Split(char[] separator, int count)
% w, L. X6 C% d$ U3) public string[] Split(char[] separator, StringSplitOptions options)
, h, Q/ c* T$ g1 Q$ c4) public string[] Split(string[] separator, StringSplitOptions options)2 q# ~) R: Q2 a" Y. s
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ ~* v5 X6 r# j2 L; ~6) public string[] Split(string[] separator, int count, StringSplitOptions options)/ M1 X7 }% R/ a( s9 o6 l
, @1 y) u% A; h2 y0 U. Q# O
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
/ ~* }  H+ W/ K' N) ?2 N, x8 Z6 R2 k5 c2 _$ m; {
1. public string[] Split(params char[] separator)
" L# T& @5 v1 g' P) k% H% x9 _- W$ O# ]: D1 s  h
程序代码5 A. M! A) m: H' n. [( x( h5 ?
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
* u) d. A4 J0 P& lstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}: I( }4 x: G2 J
& R/ \2 e" g* w( v: a1 D
2. public string[] Split(char[] separator, int count)
1 @1 h0 m8 E) q/ O* ]: B4 A5 t
' W7 N8 o# N) j1 A 程序代码  g$ q. L4 B8 p5 C7 e) \
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}: M1 i4 N6 f1 f0 t
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}& J* U- q& t$ h+ J1 d) c% u2 D
& L; A' ?: Y* O% g9 U; U
3. public string[] Split(char[] separator, StringSplitOptions options)
& D8 b! R) s& ^8 s
# G1 u& A9 w4 B- j9 m: r6 E 程序代码
+ [' R& M: x, e' f( Bstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素3 k! p& Y9 B$ C9 r
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( |/ w8 A' r+ w) p+ h  ]
* q. ~. m0 b7 q, Y3 m4. public string[] Split(string[] separator, StringSplitOptions options)$ Z" x1 u0 [: n; Y

, i" U2 L* ]0 S* k 程序代码
' a8 O3 {$ t$ a( f  _# estring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素$ U+ S* X1 O1 g- G3 x
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, u; t% A' Y/ Y3 Y- `2 L% F
/ ]5 [9 u' o0 h/ |$ ~
5. public string[] Split(char[] separator, int count, StringSplitOptions options)& g4 V0 ^' \9 L6 ]! S$ G/ z

8 J: W- c. g& N9 M3 O 程序代码4 o5 {- L3 O8 o+ m1 P
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
1 l2 ^& A1 O: dstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素9 c6 c- `1 }2 ^( j$ u. ~6 T( }
" g! C, s7 h3 M, j5 v
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
  q  t6 d& l! E
0 ^# d! {5 w5 a0 b/ T代码/ t$ w, J5 d) j# N, ]
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# z+ q% [7 u$ h9 I2 F) p: j: H+ C& Dstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-10 08:12 , Processed in 6.083242 second(s), 15 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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