晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件+ s& o& w8 G3 q5 b7 V- d  e8 s
' ~, m" I5 O4 m2 g6 g$ E4 ~
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
( d: X$ Y- e4 Q/ O5 R- ?
* i3 H7 v+ k$ P& D9 }/ i& {/ g对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
  |6 b0 f% @! Q6 q  F6 ?8 }+ ahttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
8 o& G7 |" _7 t! y/ E1 X  {http://www.itwis.com/html/net/c/20100506/8234.html
) \9 ?% U# v: \, I! M: [7 ]. q, }% N/ _
程序代码
* l& y* }# n+ p9 u* @1) public string[] Split(params char[] separator)
  U! y( }; j2 o% D+ d2) public string[] Split(char[] separator, int count)' ~; w  {5 `+ K1 A. L5 ]
3) public string[] Split(char[] separator, StringSplitOptions options)% E$ y; P1 f9 C  G# r* ]8 T0 o8 U
4) public string[] Split(string[] separator, StringSplitOptions options)
$ F  S/ m7 T3 X( f5) public string[] Split(char[] separator, int count, StringSplitOptions options). @+ f/ D8 \0 Z! C9 M+ m
6) public string[] Split(string[] separator, int count, StringSplitOptions options)" R0 [+ v0 m& n2 B( m5 t: h$ U3 h
" H8 [+ ]8 L' K) \- w6 c& a( W/ q
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
- \$ H+ C5 L6 M; M6 [1 b/ |1 w* q8 n
1. public string[] Split(params char[] separator)" D3 f9 b* t1 K: |3 m

$ O3 I% J$ A, b# i! J' G$ ] 程序代码
! Y8 Q5 m/ Z9 @: b$ W' Kstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
5 H1 d. [8 b4 o; A" T! Qstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
; |2 ]1 M% e3 b. j! B9 m) @! q0 k6 K) W# {6 n+ ^9 Y
2. public string[] Split(char[] separator, int count)
' ^: e! e- R# ~' U9 \( H
& o+ Z9 r% a/ i) `3 s$ p1 W 程序代码9 ~/ J) X+ J1 m+ g0 f8 n# c
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}6 L0 ]0 ~% `6 s% x! {
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}# y8 t/ y7 ?7 B9 k
' K* `$ y  J/ c7 y$ h6 j
3. public string[] Split(char[] separator, StringSplitOptions options)
+ V& [9 o7 x9 _% M$ `' G0 C: {; D0 ]2 k
程序代码
( v) Q' ]$ X/ f+ _5 T+ D: Fstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
; V" Q8 t. {. a# F% Q- C3 dstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
" V0 |5 D) U4 h4 J: [: v2 U# c$ a6 z: r
4. public string[] Split(string[] separator, StringSplitOptions options)* i! I! a8 m9 N% `3 }
7 m* g  I9 b: B# n# x$ @
程序代码
/ h  |& X' b  N0 Sstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素6 s, w- \8 D# ~, `
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% d5 @, x% t/ {" x! l1 d6 D) `2 f- X( o0 ]/ |2 d
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
9 f# t' R6 v" N- u9 V# c* m) t: t. F; z
程序代码
( U/ j3 S; |+ K( \) Dstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( O! g7 ?( f! @. j. ^4 t4 X
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
& h4 ]. J( h  G& j4 F8 j
' ~# d! I: z) I+ j/ a1 T6. public string[] Split(string[] separator, int count, StringSplitOptions options)
7 |5 [- X' M2 t1 y/ @' b6 ^, t, o- o( g
代码
1 k5 i: n8 f' s( wstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( G5 t; ^/ [$ c9 j% Pstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-14 19:51 , Processed in 6.074452 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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