晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
! s; s9 j: t1 s9 [1 t  I1 h$ D
3 ^3 f7 i* p: u# p$ [5 ^读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
8 j$ v4 m: W" _7 c3 r
& K! H, b/ }+ b2 @对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别+ s7 P2 A; y. O8 I: p& l
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看( d, Q# p4 J! O3 B  n
http://www.itwis.com/html/net/c/20100506/8234.html
& x- f% K) T7 `3 I  a' o: J% n6 ~5 d# J5 o2 f% b
程序代码
6 h& z  u. H$ y0 g1) public string[] Split(params char[] separator)
& a& u1 _8 Z# Q! G# z# |' U+ v+ U& S2) public string[] Split(char[] separator, int count)
8 K$ j) Z- J2 z; t7 ?$ T0 z3) public string[] Split(char[] separator, StringSplitOptions options)
- d. G2 ]: S- q# P4) public string[] Split(string[] separator, StringSplitOptions options)  {! S: V5 x, N8 J" T4 W
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
: H' |/ y8 {) e; \" t6) public string[] Split(string[] separator, int count, StringSplitOptions options)
% o7 }4 D4 M. E  h' U3 ]- O& g' o( \  p6 Q  l1 r
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):2 g5 [, ^: ]3 O5 M

: W, t% k, x* L4 |1. public string[] Split(params char[] separator)' `# F2 S9 H& a. Y! a' |' A9 `9 W

3 @9 z5 s5 ^; F5 ^ 程序代码4 J: t0 O7 T7 N; ~4 o
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}* w: F. c9 ^; g2 i
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}, m- D+ U! w6 b% H7 R. X

# Z/ s) g% p. d% U( a! q* r( b2. public string[] Split(char[] separator, int count)
$ {! o( o: Q1 f% \4 @
/ s! F2 P9 P, s2 O  O+ Q, \ 程序代码' a* X3 I. a  C. S
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
2 V6 R! j& x; U* j, T5 s  o! s. O9 x0 Z* Gstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
% t1 w# v5 a9 g' ~) u, {$ Y# s+ d1 H7 v
+ Z1 `9 L: V. R$ p3. public string[] Split(char[] separator, StringSplitOptions options)% W; ~$ U1 c6 q6 d0 m8 j4 r
& N: d. F. ~+ J5 O# X
程序代码/ F9 I* d* }/ j: {( a2 }& W
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素: L$ e3 v! m" _! f' E
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
, M2 X4 k( O  F: n$ ^: v
8 c5 F2 C4 ^$ j( k+ b- x) C4. public string[] Split(string[] separator, StringSplitOptions options)
: U  Z  r' {- I1 i  z+ `, y% q! N: d- h4 r8 z
程序代码! \5 y. h; V/ w! a
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素& L' D0 `- y" q! n/ j
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* y/ \* f' L' g3 O
0 g& G: l% o# w5 q! R8 p. c5 z5. public string[] Split(char[] separator, int count, StringSplitOptions options)* K, M  g9 A) G, e3 [8 R# r; u5 H
9 s8 Y' ~4 T- h/ o6 u5 R8 H
程序代码
, u& t6 R) ^2 p3 m& p! k8 J, hstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 t  V5 c5 |/ w& p* O* F! tstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素1 }; m6 e, ]' @

; m7 G7 ?3 x2 p# y+ ?6. public string[] Split(string[] separator, int count, StringSplitOptions options)
3 ^& {& ]* |7 B  [, }
2 F0 b3 f3 O9 l( a代码! Y4 I. I- c/ v7 E' a  V& n
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素$ }# [; ]% q0 j. _: H8 S/ b* U
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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