晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
! ?' ]* d* a. F; G# S% b/ `4 C$ P1 W
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
+ D5 m* |2 }1 c/ W" M; E: b
: [* C5 S+ e  H: D/ u4 S7 M" H- U, z对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
9 f. E$ y8 u% Thttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
1 s/ _* t7 o, B" g, E' Q+ mhttp://www.itwis.com/html/net/c/20100506/8234.html
2 ^2 F; i) ]+ d: P$ J" t$ k
! R+ }4 {+ ]7 t* o& Y' Z程序代码. k, l  F) B" n
1) public string[] Split(params char[] separator)
/ o- {7 w! ~, m3 v$ w4 x& R2) public string[] Split(char[] separator, int count)5 \+ _" y" j7 }. u8 D* v
3) public string[] Split(char[] separator, StringSplitOptions options)" l4 k3 I+ z. B. P/ Z, ]+ L
4) public string[] Split(string[] separator, StringSplitOptions options)/ X3 v: R* g, ?( g6 h0 k+ R* \( w
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
- y/ E1 s: _5 G6) public string[] Split(string[] separator, int count, StringSplitOptions options)
6 Z" z7 s$ N+ [) @& O3 j8 t8 t2 N* [
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* e! f3 D% X$ g3 G6 W$ i

. F% A1 e% n# c2 B8 b* t1. public string[] Split(params char[] separator)8 j, X5 i% L6 X/ {# i

# `9 Z  r* C5 f( ~6 T/ F& Y 程序代码0 l9 q$ S$ Y. T, L% Y9 K0 h  A. F
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
- X) x9 |+ F/ K3 h0 x# B* Q. Astring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
1 E  A0 m3 @! E2 C% Z# f
; b, A9 t, d. e" k2. public string[] Split(char[] separator, int count)
& U, O$ G! w" W
# `' y. S1 B) c/ c5 ?5 { 程序代码
6 b4 B, y" \. Xstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
% e# F3 X4 X7 Q6 p* Y. p& Z2 Rstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
1 H  O7 w7 v  a! i* {+ f, W
" S0 s: j5 T8 R% r. k3. public string[] Split(char[] separator, StringSplitOptions options)6 X% [6 q. T% A2 B" t- f1 E

8 p7 ]2 \: o4 N 程序代码
+ h8 H- Y8 \7 {, F% ^; Tstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素0 H" [' Q( G! ?; J1 L4 _8 W) A/ H  s
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素+ W  p. U+ D8 {, ~! |# @
0 v; E* ?  [2 J" T2 U4 c8 C9 w
4. public string[] Split(string[] separator, StringSplitOptions options)
  H, w2 u5 M5 u- O- H. R) v7 D! R/ h8 `/ x& d& K
程序代码# t* F: `8 h" p: v" K- p
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
& [. j2 V8 `' v4 ]9 J' @- Mstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
& u7 X8 c  O0 j( L5 O
! b& G0 M6 m' X0 z; t5. public string[] Split(char[] separator, int count, StringSplitOptions options)* h2 r# H0 P( u1 o1 j6 M

' Y# `6 F- ]. G; h4 Z( G 程序代码
/ [" j/ K9 s  F7 Z' X5 Gstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素8 z$ S9 u2 \* E1 U3 u) ?
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素' D& A& _' \# Y
- M; O( X1 q1 N7 l- v, t
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
3 E; a: e3 o5 z* i* m
! s5 Q- [& z9 g$ ?/ A1 x代码; l0 a) J  R2 t: ]
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
, U  {% v) N, W8 ?7 ^string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-25 17:30 , Processed in 6.065042 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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