晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
5 R( Y! l) T8 s, u& |
' G# P. N6 Z' Z% s% o7 H读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
0 M0 l; y* p. I& c+ t% N0 S. Y' T) L) N8 A5 F1 R
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
( u) x1 W- H$ t& i$ Shttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
7 f- I# K5 q' e+ I+ `http://www.itwis.com/html/net/c/20100506/8234.html
( v0 o" g& M9 a7 y
4 w9 y8 G5 L0 c1 G; A程序代码
# `3 M0 ~+ U4 j; A, T$ ~4 g5 b1 D7 z1) public string[] Split(params char[] separator)
0 A5 d+ o* T, a2) public string[] Split(char[] separator, int count)$ P! v, E$ `  e# F( M9 O, g/ |
3) public string[] Split(char[] separator, StringSplitOptions options)
  C. v; }- d3 d7 `4 f6 n4) public string[] Split(string[] separator, StringSplitOptions options)
! O4 T" B2 h/ s+ i9 H( h/ O3 A5) public string[] Split(char[] separator, int count, StringSplitOptions options)
& Z0 `4 W# b4 Y; J6) public string[] Split(string[] separator, int count, StringSplitOptions options)3 r0 V& ?. {# \: e
0 }0 f$ I4 ^" v/ ~% B5 }
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):% B1 U( z/ B) z: P& @/ B0 c

: }9 ]" F) T; N8 e+ F* P1. public string[] Split(params char[] separator)
% \+ O  S, ?( {8 W
* s% S4 P* ?2 B% g6 s 程序代码/ |: w7 {! t9 w; F
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
* }) ^7 q& g( D% M4 h' y! S8 jstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}4 p- u2 S% Y% V

( Y  l& l: C- t4 {- F  v2. public string[] Split(char[] separator, int count)
- l% A0 v/ P9 d4 v7 e! j$ P
/ U$ p3 y/ H, o7 d5 M, o+ R" _ 程序代码. |' e/ ]9 F. `" g
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
2 y1 \/ P" p( ?0 @6 fstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}6 ]- w: G* U2 ]; T$ L+ P- C0 h
' `( o; ~; b# {% m
3. public string[] Split(char[] separator, StringSplitOptions options)
( y' y+ M% {: U& ?2 M- @
+ F: R) e6 c( T 程序代码
# j+ O  ^1 O$ C+ v+ F. `! [" bstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素- M0 O& r& c' R* i8 J' z
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
& ?, V! H$ ]* j- _8 J% x" i6 K- L* L# R8 [; }' C
4. public string[] Split(string[] separator, StringSplitOptions options)1 @- j; C3 T- q2 w  j7 H% V, I
! `5 W% k" }' ]2 ~$ i) ~
程序代码; }. q3 \# T; y; E4 q
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
, d0 _5 |1 R0 O6 estring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: ~8 Y* D, i8 J% t2 d7 Z" c: S1 J" m# c0 a
5. public string[] Split(char[] separator, int count, StringSplitOptions options)/ D+ _8 {6 ~1 G6 H0 ~- i( A

( _' z. z7 ^$ K 程序代码* ?3 z# n' R- c5 M5 A
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 G* v' O+ ^& Dstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
1 x2 E: ]1 O9 J+ J& i+ u/ U& ?. i$ ]6 \5 r4 v, L* v& v  m7 p9 {
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
5 {/ ~( ~2 o" r" w) Y0 p9 C' L+ p8 u1 w7 P& J) C8 v# f
代码
  K! I# O2 `9 w. Vstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
2 w3 ~1 l. O( Y- p, hstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-19 22:54 , Processed in 6.066081 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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