晨鸟科技

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

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

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

. j7 Z! p' A7 R- C/ e) o  y6 e- B读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
/ |7 h+ ~3 E, `4 ]7 I" Z) ^
! f/ E7 B6 i6 `$ ~* e对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别- M9 c% {4 K, `, ^3 q( b# @$ Z6 D) C+ [
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看5 P/ F3 Q( Z. x  C! S% K
http://www.itwis.com/html/net/c/20100506/8234.html
! O- l1 T- }/ V1 R# R% H$ f) M
( Z/ I0 h/ z. o" M  s; H( b程序代码
) O. g, q8 `  J  `2 S5 j* |) Y& d1) public string[] Split(params char[] separator)# z  [; r! l: {
2) public string[] Split(char[] separator, int count)
1 g) L& J; k6 W/ c% @3) public string[] Split(char[] separator, StringSplitOptions options)
4 O: ]8 H" ]7 E5 g4) public string[] Split(string[] separator, StringSplitOptions options)
9 j  {4 S# {, S+ k! a' o) x5) public string[] Split(char[] separator, int count, StringSplitOptions options)8 a* m& n' D% ^" l2 V8 @9 x! q1 [
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
0 e4 ~5 S% I# L2 i+ Y
, A9 V0 s% z, q8 y! Z, v0 g4 b下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):' l' t9 I4 h; a; l' s7 m+ n

9 C2 {9 }5 L7 t/ a3 O1 G! }( n4 |1. public string[] Split(params char[] separator)* A3 F, g6 C: ]2 I  b; e
9 t0 V1 p* g- F
程序代码7 f- V. v+ I7 t2 o, C/ ~0 l
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}: m, G4 \# e1 d/ R" S5 Q
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
9 O4 u; z0 g( F
: ^0 |' `& A; ]) j+ R/ @. ^3 `2. public string[] Split(char[] separator, int count)
' R; A: |' ^1 a( U8 T. @" t, k& o3 K7 B3 g
程序代码
0 C5 c# q) k. i3 s% I3 m" Qstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}* a! v  e" w, ~
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
' q3 k1 I( g" _3 U9 K. r9 _" s% b% u
$ f$ G5 P3 {+ {; ?# K( _0 d3. public string[] Split(char[] separator, StringSplitOptions options)  J  L( X6 b3 x2 ^
1 Q2 e' Z, H' N9 g; |( M6 j; X" @
程序代码. d8 j, c8 u6 k2 F8 r1 }& h' u
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
, a2 A* f9 e4 i/ X9 G9 e( f  pstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* N0 e( }* i4 T: R0 T7 t. o2 T' @% G" I
4. public string[] Split(string[] separator, StringSplitOptions options)5 a4 f. C* @* y) f" i  N

4 p8 `2 l  L+ L" q: C4 T 程序代码( c4 a& w7 R8 b+ O
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素0 x8 m- C+ ]2 H" G7 [/ E  J
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 M3 I% U: u) s9 H/ _  o6 t
: `7 }! L: m* W3 G5 Q5. public string[] Split(char[] separator, int count, StringSplitOptions options)0 S5 e) {; E8 s! f5 ~2 b: h+ e, N

4 N5 ?" Q( o/ @7 ~5 R6 [ 程序代码; H0 X7 v' w- ^0 p3 G, ^+ B/ C
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素# z0 k# h' x/ c% E
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 n8 V6 j; e( q, n2 D! A& Z! ?8 o3 ~# j2 ]
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
2 I$ W, f( H/ T2 c" u5 a. w8 c+ }6 K( B
代码7 y$ b7 `' T" B! \/ `8 ~. ?
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
  M! ?1 H8 X1 rstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-16 20:58 , Processed in 6.065663 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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