标题:sql2000保存图片怪象
只看楼主
hpu02zdh
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-5-12
 问题点数:0 回复次数:2 
sql2000保存图片怪象

我用的是2005版本的编程软件 可是有一句sqlCmd.Parameters.Add("@IMAGE", buffer)出现警告,请高手指点
Private Sub InsertData()
Dim IDItem(2) As String
IDItem = CmbStuClass.Text.Split(":"c)

Dim StuID As Int16 = Int16.Parse(TxtStuID.Text.Trim)
Dim StuName As String = TxtStuName.Text.Trim
Dim StuSex As String = CmbStuSex.Text.Trim
Dim StuClass As String = IDItem(0)
Dim StuBirthday As Date = DateStuBir.Value
Dim StuCard As String = TxtPerCard.Text
Dim StuPhoto As String = LblPhotoPath.Text.Trim


Dim MyStream As New FileStream(StuPhoto, FileMode.Open, FileAccess.Read)
Dim buffer(MyStream.Length) As Byte
MyStream.Read(buffer, 0, MyStream.Length)
MyStream.Close()


Dim value As String = StuID.ToString + ",'" + StuName + "','" + StuSex + "'," + StuClass + ",'" + StuBirthday + "','" + StuCard + "'"

Dim sql As String = "INSERT INTO STUDENTINFO (STUDENTID, STUDENTNAME,SEX,CLASSID,BIRTHDAY,PERSONCARDID,STUDENTPHOTO) VALUES(" + value + ", @IMAGE)"

Dim sqlCmd As New SqlCommand
sqlCmd.CommandText = sql
sqlCmd.Parameters.Add("@IMAGE", buffer)
sqlCmd.Connection = SqlCon

Try
SqlCon.Open()
sqlCmd.ExecuteNonQuery()
MessageBox.Show("添加记录成功")
Catch ex As Exception
MessageBox.Show("添加记录失败")
WriteErr(ex)
Finally
SqlCon.Close()
End Try
BindData()
End Sub

搜索更多相关主题的帖子: 保存 
2007-06-07 11:55
frxyrx
Rank: 1
等 级:新手上路
威 望:1
帖 子:66
专家分:0
注 册:2006-11-2
得分:0 
sqlCmd.Parameters.Add("@image", SqlDbType.Image).Value = buffer
用这个试试

2007-06-07 16:44
hpu02zdh
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-5-12
得分:0 

谢谢!
问题解决了

2007-06-07 19:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-145614-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.075431 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved