晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
* J4 L8 ~" j7 J! @8 e- K/ o
% T# s7 y: V3 F0 ?& m读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
8 A* Q1 k$ X4 ~. B
  c' _) e9 Q" d* k7 C# q& n对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别' c4 L: Y/ S* n, X; S  _0 d5 v
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看0 y% O4 u4 b4 `/ e
http://www.itwis.com/html/net/c/20100506/8234.html9 M& N7 u; t/ U
0 |. ]! n' \3 X6 C( R
程序代码
4 }9 Q$ h! [$ S0 I7 ~3 e2 O; X1) public string[] Split(params char[] separator)/ J! I! y( v0 d4 U" u4 U0 |! L6 V0 c$ Y" J
2) public string[] Split(char[] separator, int count)
3 [- H  N9 _3 D6 ?( C3) public string[] Split(char[] separator, StringSplitOptions options)
* d* W+ p6 z- P/ y4 e4) public string[] Split(string[] separator, StringSplitOptions options)
: [" v7 P0 g" V- f, C5) public string[] Split(char[] separator, int count, StringSplitOptions options)
  w  j% q9 `/ p+ S6) public string[] Split(string[] separator, int count, StringSplitOptions options)
* S! U, m8 y0 F5 b; [& m9 S- n- L' G  @
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):$ \3 v* K8 t. U3 |- e

2 W0 }8 l) y5 C) z( O' u, W2 f1. public string[] Split(params char[] separator)5 ^1 R0 A; ?) ?- @7 X% o+ `
6 |8 f  U+ {" M! _& P0 H  j
程序代码+ w% g; g! m+ ^2 r6 }$ y* ?4 w2 L
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}0 a9 o) Z: h& M3 I9 P
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}2 n. R5 w1 l4 W
8 [! X! p% k+ c* l! [2 ]
2. public string[] Split(char[] separator, int count)* g9 t: z( r6 w$ D
9 @4 L) t: M7 \! d
程序代码1 G- t0 u4 O: b8 C3 c. x& P8 L2 ~* p
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}6 |$ ]5 ?; W/ f+ C' f
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}* \3 _: N8 _" I' P* h" J. A3 M

( n0 v7 j7 S5 N# [4 p# @3. public string[] Split(char[] separator, StringSplitOptions options)
0 |, K3 ^- c# v; [4 e' M  S% B% R' m" z
程序代码; k$ v" k/ S6 {1 R) H4 f: \. q
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
9 X# L& y' W5 Istring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素) P& K1 U. f. @- g7 z
, C8 B3 L& T  L. ^- M# L/ J
4. public string[] Split(string[] separator, StringSplitOptions options)
9 H' `0 f1 K; ]! ]5 D7 G9 q$ N6 F: c( p$ @: V
程序代码7 S( r4 B3 o5 v) i9 T( j" F
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
. U7 Y7 k) p# c8 i) sstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 J! D7 Z9 i, e, S! c! E2 G. I
' w* @2 e8 e/ r$ H
5. public string[] Split(char[] separator, int count, StringSplitOptions options)' v$ C5 E/ Z( f3 }6 y
' w5 W  k: g4 E' U" Z* Q9 Q7 X
程序代码6 I0 T7 Y7 w5 P2 D1 u
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
9 U; u4 {1 d  o# lstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素2 H1 C9 D- N" A: h$ j' x9 G
8 V" W6 J" W; u+ v
6. public string[] Split(string[] separator, int count, StringSplitOptions options), ]1 |- T1 A% Q  A, V$ V
  \, n  e! D0 m9 }; t, M* v2 ^
代码4 l9 y: b+ @8 @. [, f
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 H+ X/ r; r# a+ Hstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-1 22:00 , Processed in 6.068948 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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