晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件" {' J' V- C- B& v9 ^, Q

" a5 u7 J. h* v6 s5 s' S8 W- r读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码+ ?$ }( ^  `: R1 M
& {! A+ A3 h- O6 x2 T5 J) D
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
, ?5 ~# {* [1 ?% ]7 b4 }http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
4 Q# E# ?& P8 P9 bhttp://www.itwis.com/html/net/c/20100506/8234.html
7 c( Y3 p) ]8 D' s  F/ j" Z& W3 w/ i3 v1 Q! v+ X) X9 [
程序代码
* u0 n5 r  I. N% i- R& `+ D7 v1) public string[] Split(params char[] separator)& t7 |" K  X" J* T; J
2) public string[] Split(char[] separator, int count)& F* I! ]$ N2 z1 ~/ X
3) public string[] Split(char[] separator, StringSplitOptions options)
3 h8 q; t* u0 c2 d1 z5 A, k4) public string[] Split(string[] separator, StringSplitOptions options); S1 ^" R' ?: U6 i5 W
5) public string[] Split(char[] separator, int count, StringSplitOptions options)  S5 n4 h* V3 x# n  g" Y0 E! k
6) public string[] Split(string[] separator, int count, StringSplitOptions options). W6 R' K( v/ P7 \$ H4 m
# I  M0 d7 V& V+ y9 ?: T
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* n9 z" z6 c  M9 }; B# S
& O( L4 q. @7 r& b; J3 X3 o; u
1. public string[] Split(params char[] separator)( l+ O6 G2 ]. ^+ B

" O& g+ r: E% t. D- p$ w 程序代码3 v  O# P, v. e' K$ O" y
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
  h/ b5 n: o$ \' W) p- Gstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}% }/ v! c5 b$ ?; ^

# {0 x1 a1 G% q" y/ @2. public string[] Split(char[] separator, int count). h7 H) I! G5 k8 |" }: ~

, ^4 r8 t1 |3 s1 v: T+ ~' w 程序代码0 O# ?0 J% A3 h' A5 {8 V" f
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}  ^: r2 I' y$ P/ `! p& S" ]
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}! O; d0 N$ m9 u6 x" v

( d  b2 F3 M. i! z) m3. public string[] Split(char[] separator, StringSplitOptions options)
; u2 L- D4 `+ M, B* |- c- l& o. R8 m& ?9 f
程序代码1 A! i5 z4 Z" M
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
4 ?9 K8 `) P5 U8 R5 i' k  I) Rstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素9 K2 a" }9 ?. V6 A9 `1 _
2 F- Y0 b& e8 F0 {! r- C* O/ t
4. public string[] Split(string[] separator, StringSplitOptions options)2 c5 j) o6 \( [" Y& H
* T4 k$ _9 G" b, v, C
程序代码$ m9 K2 s: Z3 B1 H+ g
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素) R+ l5 `7 N7 Y# B( V* C
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
5 n5 m, G' h* D( G0 m% p
% r- C6 n% y' w, z  W3 ?5. public string[] Split(char[] separator, int count, StringSplitOptions options)' L, {5 R3 f' s# Q/ e% P9 s

0 i+ o5 w) _! q) k 程序代码
: o- Q/ p$ M* n9 f# `string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 N2 h" m4 z+ B- e6 Xstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" J9 D, O4 Y. t, `% ~+ r  m
: I6 h* ]( Y% S, h% Q1 l* a
6. public string[] Split(string[] separator, int count, StringSplitOptions options)5 s3 S/ r" b( r0 w5 |' H* K
% a" h, L7 t; F) h1 J
代码
  L  @- G0 s& V% `' Zstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素0 Z1 ?4 W0 s* k$ V# L
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-25 17:18 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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