晨鸟科技

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

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

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

. W; d, U1 w/ ~+ x, E读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码  x0 Z# }1 T4 [. e$ b, r
4 r  t- q# |( X
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别/ |8 C, t5 q2 a' s2 v6 A
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
3 B7 x1 Z* k$ P( E; g* _$ Ehttp://www.itwis.com/html/net/c/20100506/8234.html
$ P# P: u2 y2 V6 F0 |9 J$ z) N8 {3 e- ~9 n9 C$ X
程序代码
7 @% n$ Y  n* g& a1) public string[] Split(params char[] separator)* ?: _3 F5 l: a/ e' E# f- L
2) public string[] Split(char[] separator, int count)4 E1 W  L% t1 M9 x* D5 D
3) public string[] Split(char[] separator, StringSplitOptions options)
# q# T; k$ M+ ]; n$ y# n4) public string[] Split(string[] separator, StringSplitOptions options)) L, U$ u. S  O
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
- h& {: {& g% i. Q% c6) public string[] Split(string[] separator, int count, StringSplitOptions options)2 ]& [$ d. ~9 _7 {+ B8 f* ~

3 F! z" d( D8 b, p下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):( Q1 O1 t+ v0 o, p
4 G1 W7 Q% `4 V7 c- _
1. public string[] Split(params char[] separator)
8 ^) K+ D& s0 B$ _  q) H0 Q( K
: y! m( k$ [9 q9 F& l5 n2 q4 s/ \ 程序代码. k1 g. R0 Y% k
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
+ C8 n& L% o5 F- ~string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
1 @, v! S; `, r' p. V- A9 A6 u: l$ o. j6 P' k
2. public string[] Split(char[] separator, int count)
0 F3 [) |; b) q, k) g! |' T
! s  }; O( V/ `! ] 程序代码
) W, W5 O1 E2 v- K& S( m8 Hstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}# K, X; t5 C  y
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}! @8 S- \" G1 h
8 O9 v8 v8 j% f( o% i2 B+ W4 R7 v
3. public string[] Split(char[] separator, StringSplitOptions options)
2 N+ V9 }1 w7 R  {7 v  [- b  q6 T$ t( c7 h
程序代码
: J2 X4 p& ~( Ostring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
9 U! Z4 ~9 r! F2 U  _string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ `) o" Q$ _4 w4 ]+ g# m  q) Z9 D  V0 X
4. public string[] Split(string[] separator, StringSplitOptions options)
3 E8 y' L6 X+ w' j: h- |" h0 |8 g
8 V. T, N# X; Z& l$ \# W 程序代码
; Y8 l3 {( r* Kstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
0 e# [" [4 f* C; s! |6 ]! ?3 kstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素2 W5 G3 P8 o8 |* N! V# O7 v
. y) n: y3 ~& a. i
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
" l2 o3 c9 ?3 c9 _# e* A6 |# X1 q, T& ~' V
程序代码
$ M3 z& L! u+ q5 m  P* ^string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
0 f4 v  N# E+ V5 S' istring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 V( F8 v/ U5 N0 |) v

8 b1 t* }+ F1 Q6. public string[] Split(string[] separator, int count, StringSplitOptions options)
7 Z5 h! i6 W0 h- l6 z* X3 w$ P# s& J8 s
代码% z0 ^7 p! S3 A: o
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# v1 N- q! V" X6 ?- C% Jstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-26 13:46 , Processed in 6.077382 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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