晨鸟科技

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

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

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

5 v2 M3 K+ U  y& H/ p/ o8 D读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码4 p+ P$ x2 B# Y

& ?, y5 d* l6 Y. s对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别) Q1 M! P% l' l1 u+ S
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看& W" P4 Z! l4 B( c$ C
http://www.itwis.com/html/net/c/20100506/8234.html
8 d7 H. N$ p! J6 I
) u" W) Q" V& L程序代码
/ \# Y6 M5 y5 o: F4 y! _1) public string[] Split(params char[] separator)
4 [: G6 j* S) p+ g2) public string[] Split(char[] separator, int count)
$ T0 G% ?6 q& W" @0 T8 r3) public string[] Split(char[] separator, StringSplitOptions options)
  K$ x% _0 m# x# N4) public string[] Split(string[] separator, StringSplitOptions options)- D* O6 f' a; h; G" Y4 b
5) public string[] Split(char[] separator, int count, StringSplitOptions options)* W& L8 L0 n( P. G
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
, b4 Z& U$ s9 ?, G6 ^4 H6 i
6 U. T, i6 T  o( q; y" ~下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, ^6 H- Q. W8 C9 t# w

5 e* }5 h4 j* I4 P1. public string[] Split(params char[] separator)
7 G' u) @: Z- Y* x( a- C& t: s* ]1 P* W& d( V2 d( f( Q. Y
程序代码# N" E2 {3 d. N7 Q2 S  K1 v  {
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
# x! |! k2 ~* |- A  Jstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}3 ?. [( L, l5 S1 c

8 t# F! k! {& ?2. public string[] Split(char[] separator, int count)  C; {/ }& M4 h
; J5 s4 \, w2 z! l" B! |5 O$ k
程序代码
4 J! T/ e1 T7 I3 i+ |* h5 f1 t, y( astring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
- w( d" W1 z8 J" fstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}2 K5 i/ U  B' T) Z5 l& l! d! v# O
) p: f& t# C6 F( n! C7 e
3. public string[] Split(char[] separator, StringSplitOptions options); p% o; p! w% O5 b9 J
- k" A$ b, ^. f: \
程序代码$ y' j/ x9 E8 G+ ~4 m# a
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
2 [( O2 v) T" o7 fstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素8 s3 E" L& v3 Q2 V3 T
  g2 N3 ~  d  y/ @4 Q
4. public string[] Split(string[] separator, StringSplitOptions options)
! r% r( n! W) c, \- z/ T5 t
/ i+ N" X( x* [& d5 h+ w 程序代码. \) Q; F, \9 b
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
/ o; }: f  U! R3 f7 O& r2 Fstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ Z' m8 w# B& t

# H5 }* ?" `# X6 T5. public string[] Split(char[] separator, int count, StringSplitOptions options)1 j6 K: ~% V; ]# u( H0 `
. D2 Q+ b7 j5 A; a0 a& j  K1 X+ ^
程序代码8 `, a! X5 ?# ^" {6 A, W
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( A" S* A2 Z# N$ rstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, F0 a. G# [. @9 J) J( u8 G! N

* S& w' P1 E  j& S6. public string[] Split(string[] separator, int count, StringSplitOptions options)  [3 L" d* N0 ~

" x6 T( {2 L- K) T; J) w( z4 T代码
9 r4 D$ j9 h& s. u, }! Dstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素* I9 R0 F& X& H& M1 I: @4 J! ^$ _
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-15 13:30 , Processed in 6.071522 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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