晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件) E' ?( o; H( b5 [( o
3 X6 N6 k( a: N
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码! E5 x$ V" [. A5 u
" v% j+ m* B, z' w& \& \$ ^$ D
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
  z% _; {6 S" G0 S2 e1 q0 y% a6 Rhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
) c$ B! z5 L* u- }8 F* x4 rhttp://www.itwis.com/html/net/c/20100506/8234.html/ i. a+ w4 H- n1 S( p7 w- B. {
) n# t- T2 i: C  H- h+ }
程序代码* X7 g3 d+ ]  D- F) K% S
1) public string[] Split(params char[] separator)2 z+ m: o; R% h/ E, h- T# E8 |
2) public string[] Split(char[] separator, int count)% d0 N9 Q# \4 U1 Y' r3 o6 e
3) public string[] Split(char[] separator, StringSplitOptions options): h6 `" A( h3 G; @- C! j: t- |
4) public string[] Split(string[] separator, StringSplitOptions options)# }3 N" {3 f: b. }
5) public string[] Split(char[] separator, int count, StringSplitOptions options)" h) w, \3 |' ^5 w  M
6) public string[] Split(string[] separator, int count, StringSplitOptions options)# ~# a  a8 k) k" T8 L, I

1 s  i; E. F: g7 _2 K; E下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):3 ?( S& z$ `6 j( {
/ F! h. u4 w5 `5 n
1. public string[] Split(params char[] separator)1 j$ G. _5 `' e) f

4 N" s$ {5 \# L  s' M 程序代码
& u* F$ e5 c2 Q$ c! }string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}* M! y5 X7 F* }5 Y/ j6 D6 c* w
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}, S9 t- A5 E" L/ ~
' F: Q4 l' ~$ R
2. public string[] Split(char[] separator, int count)
7 m4 A/ O6 c) z* E. A7 L+ J, R, o2 M* e; j: T% o' @4 X# T
程序代码2 O) F( S2 a4 w* M
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
9 H2 O% D9 J2 U! }string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}4 D0 ^& C# Y. x* G/ D# P: F
2 p* K6 B0 L0 q" F! V& D! Y- L1 c
3. public string[] Split(char[] separator, StringSplitOptions options)# t! l9 {+ {/ B7 k0 k$ L! d

( z; }! N' `, d; }+ k 程序代码
- ^: \! i' t# Mstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# L, }, S% Z+ Y9 L7 [9 c
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
1 a3 j, g2 a) v: O% E  f7 L' z; X- }( s- W: Q  I6 e
4. public string[] Split(string[] separator, StringSplitOptions options)) c' L3 d; k' x# o- G
. t) i& n# q3 A0 I4 ~* R% C0 O
程序代码4 O" f2 K+ k6 k7 @. t  ]7 ?
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
+ C& k2 X( w9 A4 C( qstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
8 o1 c/ }; b6 u0 v/ s7 }0 I# K
/ i/ O6 ^" G; _  l8 m5. public string[] Split(char[] separator, int count, StringSplitOptions options)
7 d# W( k. o( r$ Y
2 ~6 q! R$ y, J' }4 l+ g 程序代码7 m! d- W5 {- q3 _
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素, T9 u5 O, U0 u* i
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: M5 Z; C1 i. z$ B) H* W
* Y0 f. ^# ]! i- [1 u9 y6 m6. public string[] Split(string[] separator, int count, StringSplitOptions options)% z3 u1 g  S7 \, z0 C; b+ P

+ Z5 R7 ?  _3 d9 w# `/ K代码. e& I1 p: k2 O
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 F% [1 `4 a  N3 u, S* ystring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-14 01:08 , Processed in 6.064686 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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