晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
5 F$ M+ O; I) V) C5 U2 F) u8 {" v; L( h* E" U) q; I# u
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码' A4 z# |% b, R5 s9 r9 S
! B# t) p- k4 T, ~6 j
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别" o( L3 C8 B0 K8 [' I
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看/ M5 X2 x* R0 d' {! R
http://www.itwis.com/html/net/c/20100506/8234.html
4 J9 m9 x) T- p* j4 y* m, i4 T8 O- K' }  ]1 E5 j0 S+ p  i2 `3 I
程序代码
) C0 ^. W3 |  j5 V$ C' q1) public string[] Split(params char[] separator)4 I& g2 J' |& x6 C1 k
2) public string[] Split(char[] separator, int count)2 k6 R# A6 l! v$ c
3) public string[] Split(char[] separator, StringSplitOptions options)# |4 S+ U1 c' C$ v  Q8 z) x' u
4) public string[] Split(string[] separator, StringSplitOptions options)
1 l3 N; s. a1 Y. ^3 ^: J5) public string[] Split(char[] separator, int count, StringSplitOptions options)1 w8 z5 {! L3 _
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
- X/ {, Z2 e) |# C: ?0 D# [8 s/ a. {5 K2 H
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):7 G. N9 j* Z3 G
8 y3 f+ R; z7 o" L/ V( M( g* @
1. public string[] Split(params char[] separator)
8 v8 {$ e2 S! M4 W& J9 U) p& W0 Q
  }/ y" D& g! u3 b" Z 程序代码9 k' c1 ?  f- g( B9 z9 E" c
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}1 s  r6 l- ?" t! k
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
/ S5 J: t% E+ [! f
$ U% |4 Y" D0 o6 d2. public string[] Split(char[] separator, int count)
* M3 r/ e5 B; W( e0 v' H) _, [2 N4 S6 @; L# U. e5 |2 c  V
程序代码& E" [$ m: Z  P7 n" F# f9 u0 A
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
6 t* |' f" M- n; n3 K# a+ [string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
  }. j! R8 ?! c4 s' u. S( }% {3 ^7 ^" w8 ^& u
3. public string[] Split(char[] separator, StringSplitOptions options)
' E% Y/ Y8 Z- p8 w( f% N7 m3 j* n7 Y0 a* U% n/ K, n# K
程序代码& {/ E4 A& j0 y0 {5 J9 z
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
/ [) H2 ~0 j; q' A8 B5 Estring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 U* c  z: d* q  c! F4 z: T0 M
: n0 K8 Y1 v  N& K4. public string[] Split(string[] separator, StringSplitOptions options)
" |9 j0 j7 h, ~
2 P' A. a1 {+ [( Q/ n/ r  k5 G% s 程序代码
. H' v: _! G1 I4 N5 f7 F6 Y. P: o3 Sstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素3 W" P, q* U6 o" d+ w% Z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: P, a4 Z3 o6 A4 x1 F% P
: {5 x2 w0 G- h5. public string[] Split(char[] separator, int count, StringSplitOptions options)- V0 I9 j% {2 z6 I2 m! ]2 z+ _

& w- A6 ~# I' { 程序代码. n+ F7 I4 Y- d+ }
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 |8 U: X0 b$ w+ Ostring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
1 `* d& B0 f+ N
" [, G  F1 a7 p- k! ~. O6. public string[] Split(string[] separator, int count, StringSplitOptions options)5 [! L3 C6 o) ?3 x
2 [0 @2 C8 l! h3 D$ z
代码
& v" `9 K" n$ E! `. J7 pstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素0 |: u" m& V2 e- G
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-21 00:15 , Processed in 6.070545 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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