晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
9 A8 l/ g0 e$ c. f0 _- R
9 ^* q2 m* X) j* [- m3 u& ^0 @读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
& }- f( q  n4 s) c4 Z* X+ k6 v
3 I5 F* _  b) G, }% j对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看1 I( I$ ?, ]. i) V4 t$ Z8 M
http://www.itwis.com/html/net/c/20100506/8234.html
/ Z1 w: H! {" W' y! w' M! j- r+ T4 Z# J  @
程序代码! v$ V9 J- O- i6 i# N
1) public string[] Split(params char[] separator)) u" X! s( L7 x0 ]/ z9 R. d
2) public string[] Split(char[] separator, int count)
2 T9 u' q: t! A; Z- e3) public string[] Split(char[] separator, StringSplitOptions options)
6 t/ |' i/ @, S% H9 Y4) public string[] Split(string[] separator, StringSplitOptions options)
* [$ v/ c$ |9 }$ F, \! @" J8 ~5) public string[] Split(char[] separator, int count, StringSplitOptions options)
; @' Q. v3 N5 L0 m6) public string[] Split(string[] separator, int count, StringSplitOptions options)  d9 c0 N( a) k  O  D1 E
: V3 X2 Y. h9 q8 f
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, V3 V2 w/ v, c$ p$ m3 j

* B1 p, D$ t) a! W1. public string[] Split(params char[] separator)" ~0 F9 e+ F4 r0 t$ N
" |( L, l) C' r
程序代码# c3 }' x6 j' i/ Q
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
. I; `, s) d% |( |3 Gstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}- v3 }& [  n0 O
# K2 V) \0 I! u" q! o
2. public string[] Split(char[] separator, int count)/ I; E* u- z' ~# ]0 j- W
! h+ \2 f* |. R$ x3 k7 ?/ O
程序代码3 ~' ~1 I$ i' f: u7 v9 }
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
: _1 M$ \- C) U5 L/ I' A- }0 U1 \* nstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}/ y( R, F; ?3 e# U
/ e, z- i9 N. Z8 o8 u, A1 @
3. public string[] Split(char[] separator, StringSplitOptions options)
7 [% m7 Q, J: n8 s6 P, X1 I. t3 P6 f# B1 E% {
程序代码
5 a) Z7 s" f+ Z# f* ustring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素4 x3 A+ H: L% v# @7 L( A
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
  O4 a3 p3 Y+ n, F1 V
& ~% E: Q- v& u- C" J4. public string[] Split(string[] separator, StringSplitOptions options)
+ ~! t. U& b5 i1 Y. ]" Z2 P- X) x% F+ x0 ?
程序代码6 D" T/ f1 i' e8 E0 Y
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素. b' a! i, a2 _: F! w) r# `
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
; O7 G- q% a4 [5 S& K& w
3 V( `& t/ u: r- E7 \+ V! o5. public string[] Split(char[] separator, int count, StringSplitOptions options)+ u+ d* q( p$ X4 h. G& ~" ^
4 A& E+ C' F( g# K
程序代码6 g+ R/ @/ r8 l. o
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
, @' R( x, J9 x' ~4 ^7 x9 wstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 d6 l# O$ X. v5 y3 ^. X2 t  F! t
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
  ?' I2 X- n/ f5 e+ v0 H! s2 V. X  G" s
代码5 i! F. [3 C5 k  a
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# p4 j9 @' a9 ~& [0 b/ B% kstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
* L# M: D$ ?5 u, f- d9 f  Fhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-17 16:53 , Processed in 6.066995 second(s), 10 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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