晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
, z$ G5 h) K  @6 X7 R; y$ S. t- p' @- Y8 v, C* ~& V% ~
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码: l6 T! {% K8 M  A0 Z9 @! `
$ t8 R5 w9 y) d3 X
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别) C% Y, t8 Y$ R6 R. U
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
  a6 u3 ^8 _# T( _http://www.itwis.com/html/net/c/20100506/8234.html
' i8 X. o4 V5 G4 D5 g1 L
) ~! a9 u5 N2 n# @* M4 L2 m程序代码- g% v  c* q' G+ ?+ c* A
1) public string[] Split(params char[] separator)) ^2 v. s" n' ^4 }! C5 w" ?
2) public string[] Split(char[] separator, int count)6 Q0 k4 W+ E9 i1 G; Z2 j% I9 l
3) public string[] Split(char[] separator, StringSplitOptions options)
% X( b; D$ t$ u  M) ?4 w" K4) public string[] Split(string[] separator, StringSplitOptions options)  |) f7 S1 r) R; d+ m
5) public string[] Split(char[] separator, int count, StringSplitOptions options)$ K1 C8 B2 r3 S, ~. K' W# ~; m
6) public string[] Split(string[] separator, int count, StringSplitOptions options)4 O( n! F5 L2 K7 w% @) d4 F
6 B; C0 _; u7 @5 I; a0 [+ A% N
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
+ M# V# k: e, }+ S; f
" n% W# o+ {: o( [6 t) [$ y3 y# Q1. public string[] Split(params char[] separator)
. c2 n) m3 |! R, ^3 J& E2 p3 E
0 s- c( U2 z$ J2 B$ W6 ~ 程序代码0 `* @' H( i$ t5 C5 R
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 c8 |3 g1 ]  f8 ~. e
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}3 v  Q8 B4 B. q) W, y

, R# S% T: M+ Z; B+ n2. public string[] Split(char[] separator, int count)
% n5 H/ c: _$ m2 w7 q$ g" ]; W! Z! P- g  g
程序代码! j  e6 w7 x, R1 _, {
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}, H* j( ^; R# b! f- D" y. m# h
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
7 `1 u) Q( k  u5 `( V
$ g3 S0 V3 W' B1 r$ k% V3. public string[] Split(char[] separator, StringSplitOptions options). k( ?( }& @9 s3 @* b

/ O+ C) J0 N9 R& X3 ? 程序代码
" p, B3 Q7 M$ I4 T+ ?( vstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; b' n+ {$ Y# m0 f& |
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素8 g3 G# B$ c! t
, g- w4 `- a; S$ k( j* y( m
4. public string[] Split(string[] separator, StringSplitOptions options)) T) j# n% l) k( {( {* m0 R
, l: g' Z  K$ l7 t: c
程序代码
# d: v6 P2 _: Gstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
* s4 Z" M* x  Z& @string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素: }' j% x4 T5 `- {

/ s. k- x0 }% ^; G& P5 T+ g5. public string[] Split(char[] separator, int count, StringSplitOptions options), J  \  G: v4 l) A2 [% T. m
, u9 ], r$ `$ N0 O+ i5 w3 A
程序代码
3 h) N' _' t7 u5 a7 R% rstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! d, o+ N" j  P1 V
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 G& m# [% m" h7 [" x
5 q: w8 H) ~+ W, N6. public string[] Split(string[] separator, int count, StringSplitOptions options): t6 X# E5 f" p) F9 U8 ^* |

3 Q6 Q7 ]( Z* w代码& v+ {( L+ B( R1 _* L: x3 H
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
1 F; ^) x7 I9 Pstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-2 19:20 , Processed in 6.068948 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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