晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件$ x; q# K! z, Q  w9 u6 P* ?

4 _* ~) g7 w2 e$ x& Q读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
) |# z1 q" ~) X5 \- h  a6 b5 i/ @
0 p6 F8 w: v8 B; S2 s. o- l# y对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
' ], G0 y8 w9 @$ Whttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看* x1 w/ R4 P2 q4 Y, J# x
http://www.itwis.com/html/net/c/20100506/8234.html
: u; p9 n' {- {0 r! _" o1 B8 r
程序代码
3 K3 e- L6 u9 p/ n! x1) public string[] Split(params char[] separator)  R  ^% A- O; q/ d; \4 ~# V4 A
2) public string[] Split(char[] separator, int count)
7 G  m- r' z  \  R  L3) public string[] Split(char[] separator, StringSplitOptions options)6 `2 Q5 ~- Y9 e* Y$ b* v/ [: X. _
4) public string[] Split(string[] separator, StringSplitOptions options)
2 @7 `) ~9 L3 y( n8 a3 z5) public string[] Split(char[] separator, int count, StringSplitOptions options)
* I! _! C3 Y" G6 _; w; c6 E6) public string[] Split(string[] separator, int count, StringSplitOptions options)
% M* J! Q6 y) I2 B2 j7 f  O
( K0 Z1 p: C# V5 c) `2 t下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
- R! {: v* h8 Y8 R9 E0 T' i5 V
0 t7 }  }( T+ k& K! H1. public string[] Split(params char[] separator)
% v2 m( I. i! E- r* C9 {' p+ |" Y4 M3 S4 B
程序代码
! N% r9 p7 ~4 X8 r3 ~! Qstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
4 h8 V9 l  w4 f8 ?6 o' d8 Istring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
+ X/ J1 s8 ~. m/ b1 i; |3 t1 O
: ^$ x. Q: T! u) U0 a2. public string[] Split(char[] separator, int count)
% Q/ O5 @+ e  X9 b/ _; Z8 m6 s
% Y- |2 g) f. K 程序代码
7 c' h: P0 ?. q# B! gstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}5 B' k2 U- I/ @' o* b
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}/ u! q. h$ C/ Y
7 U* c6 R. a7 Z4 m+ b" u& m
3. public string[] Split(char[] separator, StringSplitOptions options)
& Z" E- f5 U$ c% t. f+ W" j
/ K6 l4 U1 [5 I* V 程序代码, I4 k! T3 d& W( ]& c, \9 r; C9 W
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
2 |: s" n! `: L9 t7 U2 Q9 Astring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
" p+ R  m5 ^8 v! A
" X/ V4 P0 ~. H4. public string[] Split(string[] separator, StringSplitOptions options)
6 D* p# L% L  T$ j; ^, n" \7 ]1 h
/ f7 N: x/ Z8 H& d" ^0 H6 z3 v2 D 程序代码" Y+ q6 n# X. W1 D! D6 Q
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素2 u8 f, w) ?1 I7 O9 {
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
/ _2 x  Q& b6 s$ ^. I& [$ K# ~: |. V3 F
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
' d  ?- X& K0 {9 _; @
4 g! U/ S: y$ E( O/ ? 程序代码7 U4 {  M6 f2 C# J0 E
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# i( Y+ y- j1 J- k, K3 m7 gstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 k: F* |5 m( o! y
" @1 h( K  T2 D: v" Y) L6. public string[] Split(string[] separator, int count, StringSplitOptions options)0 _  ?7 S# ~# Y4 t) y' N

1 v% k5 H4 b- a$ E4 m# `/ ?代码7 L- g; g( r. C: @
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# \) Q4 T* O" {$ Zstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-24 23:05 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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