晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
. S+ z- E1 l" z( a$ [1 M5 t" F) l9 E' w/ D  o3 }
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
0 J$ B# V( B* d5 @) ]2 ~5 H5 Z% b, ~6 o$ J7 k5 Y
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 显示全部楼层
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别, T( |9 Y! U4 l  q% G
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 显示全部楼层
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看6 D5 V( M* c3 v# K9 B
http://www.itwis.com/html/net/c/20100506/8234.html
4 Q) j; R  `5 t5 j- O/ a5 A6 Z& F7 M( V/ J9 g1 Y" i  J* C. O
程序代码8 b1 C5 R; \- V/ C
1) public string[] Split(params char[] separator)
1 H5 A1 L3 S' s1 e2) public string[] Split(char[] separator, int count); `* i+ q+ I' k' r4 c- X; J* R
3) public string[] Split(char[] separator, StringSplitOptions options)* y1 d! M' F; u& x, x
4) public string[] Split(string[] separator, StringSplitOptions options)0 K$ w7 J' D1 k4 d7 A$ c, k
5) public string[] Split(char[] separator, int count, StringSplitOptions options)4 i" h  v0 h$ f- l2 J
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
$ R5 r( j3 `. A3 Z& q0 [; d
  v; p) x1 P, q( C& s下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
/ y) P$ e' G# Q) F- F; ~' T! u" z& I4 a. K  V5 M' I8 J
1. public string[] Split(params char[] separator)
9 A( Y5 {8 ]8 E- K3 g$ {+ f
- F, E% H* V1 w. f, {* c# u- A 程序代码
3 f( |; _( p, O* Fstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
# @. s( d  p1 W) P% Cstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}; v( X5 X" y, Q- }* w# `7 [$ b

( j. F! M, [! Z/ {; t. G! c# T2. public string[] Split(char[] separator, int count)
5 {  I8 _2 _. T/ U3 r4 D
: L2 n4 ]0 J4 V5 Y, ^7 _; k 程序代码
* q& R" W/ o2 i5 Tstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
* w4 C7 h6 G6 y3 E# Tstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}1 M. D4 D8 ~9 K1 n0 B0 y" t1 F1 N( v
3 V9 ?$ C0 P! r2 i/ A) v7 |
3. public string[] Split(char[] separator, StringSplitOptions options)
& A5 M4 @/ O3 C
* W( `( x( g. y6 Y 程序代码
1 h: E0 T$ J8 M* ~/ Sstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# D" t. j7 ]8 D! E% _/ P& q
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素0 K% P+ n: f$ A

9 Y2 ^3 J2 I0 H1 o5 D5 Z7 w4. public string[] Split(string[] separator, StringSplitOptions options)
7 n) N( m5 T" b0 A* V5 T! |% R5 S" K" K# w, X: U: c, K& O
程序代码
# j' |0 b- L+ R6 ?! Y/ ]string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素( J. E& z8 H4 w
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 h3 s( b9 J+ D$ K5 L* i; R( j$ [" P* t9 q( r! I1 H7 H* v0 s
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
- C# I; b2 ^. p$ z" T. v9 Y
- J5 b! J- x6 Y3 }* ~ 程序代码
5 |0 D- j4 v6 ~* J; h  \  M% gstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
- n1 C7 |6 v2 A0 L+ Rstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
$ X/ P( x- g1 m& J
/ V. d% I0 U; B( ]1 g6. public string[] Split(string[] separator, int count, StringSplitOptions options)5 F9 n) ~4 t% W; E
: L; G' t9 [. T! T& C$ Z- L
代码$ y( _8 U, w9 d. J
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
+ a/ K$ e- S& I" a& v9 Sstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-19 09:08 , Processed in 4.905462 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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