晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件, T: I& @/ e) L! F4 q- L" l
0 ~, ?8 a" \  j# O
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
. O3 m4 s7 T. [" g5 K. |4 y( ?9 }' i% M# u& V, \
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别1 T1 M. I0 B; d0 i: w
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
5 F  h9 t: ?9 U  K* ~$ D$ S, f& Hhttp://www.itwis.com/html/net/c/20100506/8234.html9 v" b- ]( W& |6 m: v  S# f7 _
& z+ S4 h& w2 x* \
程序代码4 u3 V. T4 e' X# L! `, q) Q# @; A& }
1) public string[] Split(params char[] separator)
( |) `  y6 F, \. |9 u9 a2) public string[] Split(char[] separator, int count): V+ e# A2 D! A1 u
3) public string[] Split(char[] separator, StringSplitOptions options)2 V# l& W0 R4 u
4) public string[] Split(string[] separator, StringSplitOptions options)6 T/ u2 l6 R" ]$ N
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ Y2 ~7 r4 m( k0 a5 F7 Q6) public string[] Split(string[] separator, int count, StringSplitOptions options)
8 {; k0 H) L# Z+ ~8 H
- g; `$ F& d8 ?' y& z  k' Q下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):. z3 B: ]9 ?3 o+ J: t4 g

( F  F7 s! ~9 b$ I3 |. F1. public string[] Split(params char[] separator)
6 _& J' T+ G" ~# Z9 f+ z) S
6 n* w1 x* X  N% y% h/ h 程序代码% P9 Z7 s2 {* o; O. o3 _4 X# c
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}) j- O- M: B* l9 X! c8 |/ k
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}3 P8 [0 f- B6 T: Y6 ?
5 N0 l0 j3 m) C( a5 a5 q
2. public string[] Split(char[] separator, int count)* v+ E& ]# a5 Q9 e7 c9 n; `8 l( R

8 @5 s- P0 z9 I! ]+ A* W 程序代码' P0 @+ l8 `& K3 \0 P- N* g
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}" K' u6 v4 q7 N* @8 \0 |7 S+ J
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}; d5 |0 r* p2 I

9 r9 f) N' a3 D1 l. G3 j3. public string[] Split(char[] separator, StringSplitOptions options)
7 s. a& \2 V% v: Y1 v
. m% f5 T0 r1 w6 [) i6 H- N8 r 程序代码
# o* l, K& x0 e8 ~9 q$ _string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素+ a2 M; V( B( o0 ~0 ?
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素0 z* d' j) c* e1 M2 V  `. ~: e
  y9 ?% }" z3 \
4. public string[] Split(string[] separator, StringSplitOptions options)
/ v2 H9 M) h4 _2 u. r" g2 r3 |# Z8 ^3 m& r% a4 f
程序代码
" x! G5 M9 L* y2 {string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素3 W) _9 `( Y8 [
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
& g1 X* I8 `6 V1 z$ [, Y: w. b) h, w
5. public string[] Split(char[] separator, int count, StringSplitOptions options)3 v0 _/ f* N; H& h, x

' F  R" T# z0 t; Q 程序代码
) i& _1 E; l. B3 j+ hstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素. W1 ], T- I! |; t& w
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素4 R  O' q" ?4 g0 s
0 H$ Q, Y2 i1 @" I: ]
6. public string[] Split(string[] separator, int count, StringSplitOptions options)  }# {* ?) o/ ^' t# j! s% ~7 v

$ h3 u8 t6 E- \4 Z代码5 G; _( C' ]) ]. F4 o! Z! i) d9 K
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# Y- C1 o! z; j, o+ Z" D* Fstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-22 21:42 , Processed in 6.066640 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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