晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
; d5 I" t& D# `! V$ r; ]: i6 C0 ^) I# E( i# P/ V# ~, e, K5 Q
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码! b3 V7 V/ |' ^, {' x% E
, }3 T  K" C( U" p6 s* \  x
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
( \' y; T+ F: w( Whttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看! o; w+ Z$ V3 F
http://www.itwis.com/html/net/c/20100506/8234.html1 m& c0 b/ Z4 |/ z
2 c* O% U) ]5 u+ r  K5 S- ~2 l
程序代码
2 q; E" @; k. m  s: l% n. X3 ^1) public string[] Split(params char[] separator)
% y& a* @! W  ~) }2) public string[] Split(char[] separator, int count)
. R: W) v& V8 S: s3) public string[] Split(char[] separator, StringSplitOptions options)
6 D* ~: ?/ a# s* \3 }% ]% G, ^4) public string[] Split(string[] separator, StringSplitOptions options)
/ L. o! U+ x8 _2 R. G- K5) public string[] Split(char[] separator, int count, StringSplitOptions options)
; X% r6 H4 }3 j$ y6) public string[] Split(string[] separator, int count, StringSplitOptions options)5 T. O7 \0 B* }2 x# r

4 w- f) G3 L* u; I/ i- _  a/ A下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):; ~& W/ b$ R  ^! O# q" Z3 Q
* v& B6 N7 V7 J( U* `" v
1. public string[] Split(params char[] separator)
+ P2 g7 G! r4 M6 p5 R6 M% a  i& Q7 y1 Y  H; w1 n  W$ W/ x. x7 E" h
程序代码
4 M0 q7 i1 }# {+ e0 k* o$ E4 [string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
/ y: {# V8 {1 jstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}: P7 q# c2 j$ S  F. B

% A; P" z: T! |- u- ?2. public string[] Split(char[] separator, int count)
7 Q' F: L; ~- j/ \. r4 D+ L) Y* ]6 Q  s7 B+ ]8 A6 p
程序代码% z+ _% Z# n8 Q  L5 |( W3 [
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
- ?! L, m6 `, h3 V; a, ~string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
0 Y& x/ K- z# ~, Q' E
; O/ m6 O6 Q. l* q  \3. public string[] Split(char[] separator, StringSplitOptions options)
9 N) |# E( \1 j3 p$ y2 ^$ l5 @4 f9 ]0 l! V6 S
程序代码7 E+ @5 ^+ `% H+ x
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素" w0 V7 T+ Q/ d& @: y
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% Q( `% r9 X/ ^% X8 V8 b' O
( b+ p8 S% N! L+ X4. public string[] Split(string[] separator, StringSplitOptions options)
1 x  ]- b2 `5 m- o$ H
) |# t1 F' P/ I5 P. `0 C( x4 W 程序代码
7 Z, f" W. H/ R- H* U* hstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
4 `0 S' |1 s% w, X- n, `+ sstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 {' Z- r& t6 {' |# k4 {" h

0 k+ K8 G# k! r* V% q4 J5. public string[] Split(char[] separator, int count, StringSplitOptions options)
8 E' l  F& m/ R" ^! |( x# S9 s# w) b* X$ w! {9 ]
程序代码
8 l; |) J2 S$ C( sstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素' b7 D# i4 s; r
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素6 w0 E6 J( f5 Q* M0 O) b, @) |" u" q

+ T; k/ O! g6 O' K  w4 q6. public string[] Split(string[] separator, int count, StringSplitOptions options)
! D$ T2 ~! X8 L  x' r, a2 Z3 b+ Z0 Z" A
代码
6 a% Z, }* e) h3 Nstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
  D8 \2 W( z/ d! Astring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-7 23:05 , Processed in 6.069924 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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