晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
8 U3 C$ w3 r& g4 J" n0 J. x+ J* q3 B; Q1 E. E9 i( X9 }' ^" i6 T
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
5 {# F8 Q: m) [  a8 j4 e9 L" @6 _( [
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
5 W, a4 z9 I9 |4 Chttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
/ D) L) ^, i6 ^http://www.itwis.com/html/net/c/20100506/8234.html' [5 @: ~" G: u% A6 j

; V3 H* ~( F4 t9 B1 `/ g/ h程序代码* k0 W5 G, Z# D% z9 p
1) public string[] Split(params char[] separator): O5 a0 N0 R2 i0 U; @2 }' y
2) public string[] Split(char[] separator, int count)3 `% k$ q* ^: }( _7 j
3) public string[] Split(char[] separator, StringSplitOptions options)2 B# t( D5 c; ?) @7 c  D
4) public string[] Split(string[] separator, StringSplitOptions options)  f% N. H; m9 i! ?8 L4 i. f; |
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
6 L+ h; E8 B1 a% z$ `6) public string[] Split(string[] separator, int count, StringSplitOptions options)
  t6 x5 [! c6 t- X! R( _2 O; u( _6 c! u9 `; r
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
& |) ]' ]/ h7 _* b
8 O8 j" j1 W! Z, Z$ v6 z7 F3 i1. public string[] Split(params char[] separator)
) K, d9 |! l- }) A  y2 _* X2 I
- S, b3 Z$ l1 m* S- i# _; T" q 程序代码
: p: P) c) k* k8 i. {string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}: ]5 {* ]% z0 K" k0 R
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}$ L# Y5 P) b- M- e" y3 c
8 d; N8 o8 x; _' m( o5 W
2. public string[] Split(char[] separator, int count)1 p/ E! h8 f. W2 g6 v4 Y1 d- v, O

) j( N" |% `0 w: ?+ } 程序代码
7 P$ i* o0 \* O3 |string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
0 A4 g4 ?9 I! M! Hstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
; Q( V7 r- y# D) H9 j' o! M( N! o" ^! w
3. public string[] Split(char[] separator, StringSplitOptions options)
/ c! I  m$ Q$ w4 {8 _; Z
/ b3 v4 A, q) x0 J! G/ _5 ] 程序代码7 y8 d6 z7 V% X3 X" L# ^5 b, X
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
% m/ Q" v- p5 W  ]string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" s% t# d- }- p+ ?

5 i; I9 ^, M6 p& Y4. public string[] Split(string[] separator, StringSplitOptions options)
+ S! }4 \$ K5 n9 w; v% R3 p1 @) Y7 R4 r% I* B( J, G
程序代码. p/ f7 J1 c0 ]7 A. O/ Z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素4 d+ s# ]! l5 R8 S: }' b; ]9 M
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ }, j! G& G; t. W/ B* T& \; v# v* ]- e# M* w" \" @4 m/ A/ d
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
8 m& o) O6 m3 w' U  r  N$ w- o; b$ Y* r/ |4 L( X. V/ p
程序代码
5 U% j. a7 M4 cstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素$ h, j5 d, o4 y$ N
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 o% K! C' q+ q
9 R+ {! q; e8 c" A6. public string[] Split(string[] separator, int count, StringSplitOptions options)! J  s+ G* p, g6 I9 Q; f) _

7 I1 s' W3 z" e5 a  T1 \代码
& c1 o  N- D3 j5 Tstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
2 ]  J0 D1 o% F; \string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-30 00:32 , Processed in 6.067616 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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