晨鸟科技

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

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

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

9 ~) c  }5 z: P5 m% O读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
* h% b6 n+ `; x$ ]7 \0 ^! m2 v# c
. F1 `$ N) h. q4 l5 g/ |对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
( Z: w  \4 D9 Shttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看4 ~. F$ n9 b2 v& b6 j
http://www.itwis.com/html/net/c/20100506/8234.html& Q) `8 k9 ^2 R" ~2 N
3 a* X0 f9 r' m
程序代码6 U2 ~: j1 X4 i* g( T8 f
1) public string[] Split(params char[] separator)
3 M6 H( \3 W1 g2) public string[] Split(char[] separator, int count)! U: K9 j8 j8 B0 T4 }
3) public string[] Split(char[] separator, StringSplitOptions options)
7 N# Q% W& y! A4) public string[] Split(string[] separator, StringSplitOptions options)
" _5 X$ V' p- J$ I$ F9 @* ^+ T$ w5) public string[] Split(char[] separator, int count, StringSplitOptions options)
& D$ N  a5 f: Y# q5 i6) public string[] Split(string[] separator, int count, StringSplitOptions options)/ n5 Y- m+ {  [& i1 r+ ]; _" l
2 L$ D2 f1 E3 a( L0 i* `
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
/ y7 w- |3 V5 f# y% @
4 M( `( B3 C0 a7 L8 \3 _6 t4 m1. public string[] Split(params char[] separator)
7 M' r1 ^1 V' L: N3 x* [1 U+ W) P( W# d6 q5 R8 }- K. G
程序代码
' A9 G- j. U& C, Dstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 G$ @5 U! W# ?, x- _
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
! T9 I1 Z2 L. v
( C' }/ O4 ~# `5 X2. public string[] Split(char[] separator, int count)4 F; F, N5 o' G% i% D" r

9 W- W- s' O# ~2 X2 Z* Q* c 程序代码
9 ^" U5 Y' ~' c  m- u/ [string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}9 E* }" ?* Q/ S% T& }$ U
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
" m6 D* V7 d. {, t! _2 ^2 R
7 E/ E9 l; B9 \* Q& a3. public string[] Split(char[] separator, StringSplitOptions options): U2 A( ~# Q; e3 w) r! x! B0 P

- b4 H9 R- H: I' l' f! A) _" J) X( I5 H 程序代码) }6 G- Q" V4 _( v# M, U
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素% |$ V: w5 s  \7 H3 Q! v1 H% s* {# D% n
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 Z0 M( [8 s: V; y/ l6 g. j
" g* M, l2 B; Z; D: e+ z, h$ n- D
4. public string[] Split(string[] separator, StringSplitOptions options)
- `6 z9 K) g6 S* |. W. \1 c( t; J, P
程序代码2 o( {$ R% H$ @# J2 x2 N
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
4 A9 M5 j$ N5 i( J0 l5 `* U# v1 |* _string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素+ X: w+ `- E6 B' r" u
" k8 k9 ]' ]  a: G7 F. _8 t
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
* B9 e0 p: l, Y/ M* X  u. n
( {) s2 p2 ]! ]  u3 m 程序代码5 l5 N, q$ Z/ k8 D6 Q; i
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
) ]  e6 _% @! R1 G/ ^; S8 H4 wstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素$ [8 D6 c5 H9 b' w; C1 B2 n0 c. F0 _
8 r3 k1 Z1 L+ _9 B& S
6. public string[] Split(string[] separator, int count, StringSplitOptions options)8 B# G$ a8 }* T* e' k& d

: p1 m  b: {$ G3 Y' K/ ^代码, ^( T4 N7 c8 ^; X2 X
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素) T* t# h  E" T5 ?! i
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-5 04:11 , Processed in 6.068592 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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