晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
/ O* D8 |2 |' i
: C5 l( ~9 r9 d, U# z读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
# w4 ^, b4 F! T, P3 Q6 o1 p8 i# C! X
, \% `# b( R+ g) Q- U% O对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
  M" R4 N6 i+ C; Z# a7 Phttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
! Z- D4 |  {8 y8 Nhttp://www.itwis.com/html/net/c/20100506/8234.html
( n0 L; C6 D( \0 m, t) T0 t* B
0 Y' ~* z! q+ @2 R( J# S程序代码3 y& e0 P1 a5 u) y
1) public string[] Split(params char[] separator)
2 O( O7 c/ `" u( [2) public string[] Split(char[] separator, int count)
$ S' O; |4 U) a: M& d3) public string[] Split(char[] separator, StringSplitOptions options). k- z! t- ^! p
4) public string[] Split(string[] separator, StringSplitOptions options)% H  K0 g) {( L5 D/ Y1 K
5) public string[] Split(char[] separator, int count, StringSplitOptions options)) P* W6 F1 u: u4 I- r/ `6 U" w/ B
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
/ e9 {4 c% Y0 G1 L+ }6 v
+ t) j9 g2 g; i( p2 Y下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
+ u7 q( ~/ j8 |. J
0 t6 o% @5 u5 m' A8 T) w1 \0 ?1 i. a1. public string[] Split(params char[] separator)
7 c, g$ X6 W! P
, n7 y% ]& v# N* s& n 程序代码9 ^. s0 [- r' G% {& ]$ w0 O# o. p: I- N
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}" j- C5 h* Q" x) B6 I: F% z
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
4 a2 K# N7 o. J( b0 d% L
' n; I, f1 O1 L3 |2 s: ~2 h2. public string[] Split(char[] separator, int count)# W2 S1 t' y" `* K# x' D) ~

, y/ L: t% t5 `  | 程序代码3 A9 {, T" }+ H8 G% }3 n( Y1 Z; K
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
' k# p  |1 M( T5 z6 w# ^8 S5 Astring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}5 U" p( m" C5 W0 i) C3 N! C" l4 o
! s' P( \$ x8 S" J/ W
3. public string[] Split(char[] separator, StringSplitOptions options)
1 D3 x* {/ [. T6 B# @6 o3 {; D3 w  a6 k0 E9 s
程序代码
" O" e4 l! D$ d6 t7 z1 \string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素$ ~& U4 I: ?: ]
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 r! b! r! u0 n* V- x: S

: Q. r" }0 h. k+ P# d; p4. public string[] Split(string[] separator, StringSplitOptions options)# K" i. ~3 v5 F, Q, d* ^5 u
* y* J2 W8 ?% B' b+ G. m
程序代码
! \) b: `" x: M4 fstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素( g% E* N! e% N; _
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
; [* g  F& h9 @0 Y  M6 I' v4 |' {* P
7 s& {- G" _& r- C8 N6 x( q5. public string[] Split(char[] separator, int count, StringSplitOptions options)
" e( o1 Q; `9 K+ A' L: n1 i
, L& Y8 q/ w# j. z% M; N; Q 程序代码- Y/ l( S: {# }6 I) ^& [9 O3 W6 z% f
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素9 ^- j* S9 t3 g( Y5 L  S$ X
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 N' D$ z$ \7 I: K# G5 m- U

( a% q; Y+ c8 q: F  b: @6. public string[] Split(string[] separator, int count, StringSplitOptions options)
' B. l1 Q3 @7 S3 {- X& h" B& a$ q2 R9 }9 o! g' h9 \
代码
1 U; r# t3 e6 B" }string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
; S. ~$ o8 X8 k" Qstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-6-27 13:28 , Processed in 6.069924 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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