晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
& K% d  q0 r' ]& m! b, b
1 L/ p3 V! ^# D- g" X读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码4 Y# x' Z' f' E# r4 J* t
' z# h7 K# y. @6 h
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
. |1 L7 m1 H1 C' D/ v9 y) Uhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看# e* \9 X8 A4 o( t3 a1 x+ `2 D
http://www.itwis.com/html/net/c/20100506/8234.html
6 {/ O6 A+ Z; b; ^# I# S2 q/ L) H7 E5 j
程序代码' I+ |6 E4 Q# i  G+ E/ Q, |. @  c
1) public string[] Split(params char[] separator)
2 F3 M8 o3 L, o3 B2) public string[] Split(char[] separator, int count)* B7 B- d) l' j$ ~. A5 T
3) public string[] Split(char[] separator, StringSplitOptions options)
: X: a7 x6 V/ t; S  l  l4) public string[] Split(string[] separator, StringSplitOptions options)
: B- t( j( B, C1 v9 D" |5) public string[] Split(char[] separator, int count, StringSplitOptions options)
: f) g- I/ f/ j4 n2 u( Q6) public string[] Split(string[] separator, int count, StringSplitOptions options)& d0 e7 j7 ]2 ^! f2 k$ o3 [
9 g- u5 ?# G* J# j) ]& n, B
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
7 J6 v+ T. J# a2 w$ H# S- A9 X3 X. Y, ^6 g+ n" `
1. public string[] Split(params char[] separator)# d' |+ y$ N. t2 ?! B# e4 ]
7 }- ?6 S3 G# h) \% x
程序代码- L5 q5 E0 b/ Q* S
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
. P3 S2 F* U! @1 X. y. Astring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}1 C$ D& W5 r  N# p

/ G1 a6 `9 c  C9 I% o4 d2 F) e2. public string[] Split(char[] separator, int count)
1 o! V( i* L/ v* K/ v2 l6 O* m$ d- Q: f5 J. V, x4 u) J$ b
程序代码% d- i9 [0 o# f& N  x0 f# S
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}8 z5 L; y" A  y' o
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
5 O2 u9 I7 h% t$ J
+ r% m2 O6 H, Z+ Q3. public string[] Split(char[] separator, StringSplitOptions options), Q/ Y, z" k# Z! G0 U0 k- h5 ?0 u
4 j5 _- ]9 g/ v! i' S! W
程序代码3 Z1 X, z+ k* H# d
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素( }( h2 z/ U6 [. M4 s- X/ E" H
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素  g2 Y2 R) @/ u# f

4 u4 U; ^- T* a8 g4. public string[] Split(string[] separator, StringSplitOptions options); `. D$ ?# O" @( K4 b$ W' r
% ~, A. w0 K! S( c2 e( R: v# u& X
程序代码# Q" N; f% b/ ^* V) w# {/ n
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
' Q  q4 O) Y: ~- xstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
- K) S1 v- A$ H4 h9 y
$ `8 N: s! E! b; }$ v; U( R# O5. public string[] Split(char[] separator, int count, StringSplitOptions options)" [+ Z; N  D- b

3 X& K6 X! u7 U' O3 Q 程序代码1 I: h# k- B, D" C7 X5 e, V
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素' N' A; Q2 K, Q: H4 D: x& t# e# M# C
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* _& W1 R7 z% I: L7 [; m
: n; t' T+ T3 [$ G; D. ^: _6. public string[] Split(string[] separator, int count, StringSplitOptions options)- f) C0 f. K4 Y" M% [+ r5 r
4 ~4 l( d. ?! G0 B2 a4 @0 q8 e& ^
代码
& \9 a3 t/ @$ n2 wstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素' p$ ~  f& j% N3 r( P. t# j3 ?& [& e
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-26 01:36 , Processed in 6.072499 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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