chenxu4277
博客园
社区
首页
新随笔
联系
管理
订阅
随笔- 11 文章- 0 评论- 4
2008年8月9日
DataMatch
posted @ 2008-08-09 09:06 陈旭85 阅读(83) 评论(0)
编辑
事务执行sql语句
Code
public
bool
ExecuteCommand(ArrayList SqlList)
{
con
=
new
SqlConnection(str_constr);
con.Open();
SqlCommand _command;
bool
iserror
=
false
;
string
strerror
=
""
;
SqlTransaction SqlTran
=
con.BeginTransaction();
try
{
for
(
int
i
=
0
; i
<
SqlList.Count; i
++
)
{
_command
=
new
SqlCommand();
_command.Connection
=
con;
_command.CommandText
=
SqlList[i].ToString();
_command.Transaction
=
SqlTran;
_command.ExecuteNonQuery();
}
}
catch
(Exception ex)
{
iserror
=
true
;
strerror
=
ex.Message;
}
finally
{
if
(iserror)
{
SqlTran.Rollback();
throw
new
Exception(strerror);
}
else
{
SqlTran.Commit();
}
con.Close();
}
if
(iserror)
{
return
false
;
}
else
{
return
true
;
}
}
posted @ 2008-08-09 08:59 陈旭85 阅读(39) 评论(0)
编辑
c# FTP 上传文件代码
Code
//
关键代码
using
System.Net.WebRequestMethods.Ftp;
NetworkCredential nCredl
=
new
NetworkCredential(FtpUser,FtpPwd);
private
bool
UpFile(
string
filename)
{
bool
status
=
false
;
FtpWebRequest ftpQ
=
(FtpWebRequest)WebRequest.Create(ss.FtpUrl);
ftpQ.KeepAlive
=
false
;
FtpWebResponse response
=
null
;
ftpQ.Credentials
=
nCredl;
ftpQ.Method
=
WebRequestMethods.Ftp.AppendFile;
FileStream fs
=
new
FileStream(filename, FileMode.Open,FileAccess.Read,FileShare.Read);
byte
[] bits
=
null
;
if
(IsLimitSpeed)
{
bits
=
new
byte
[speed];
}
else
{
bits
=
new
byte
[
102400
];
}
int
rlen
=
0
;
decimal
filelen
=
(
decimal
)fs.Length;
long
rdcount
=
0
;
int
v
=
0
;
long
sd
=
getFileSize();
Stream requestStream
=
null
;
if
(sd
==
-
1
) sd
=
0
;
fs.Position
=
sd;
rdcount
+=
sd;
try
{
requestStream
=
ftpQ.GetRequestStream();
while
(
0
!=
(rlen
=
fs.Read(bits,
0
, bits.Length)))
{
requestStream.Write(bits,
0
, rlen);
requestStream.Flush();
rdcount
+=
rlen;
if
(Ev_UpFleSub
!=
null
)
{
v
=
(
int
)(((
decimal
)rdcount
/
filelen)
*
100
);
Ev_UpFleSub(v, rdcount,
this
.ss,
this
.pb);
}
if
(IsLimitSpeed)
{
System.Threading.Thread.Sleep(
500
);
}
}
if
(requestStream
!=
null
)
{
requestStream.Close();
}
fs.Close();
}
catch
(Exception ex)
{
if
(fs
!=
null
)
{
fs.Dispose();
}
try
{
if
(requestStream
!=
null
)
{
GC.ReRegisterForFinalize(requestStream);
}
}
catch
{}
throw
ex;
}
return
status;
}
posted @ 2008-08-09 08:56 陈旭85 阅读(2531) 评论(1)
编辑
公告