我是这里的初学者,我知道如何解决我的问题吗?
我创建了一个程序来在SQL Server中保存图像,但这不起作用。
错误:
类型的未处理的异常 'System.Data.SqlClient.SqlException' 出现在system.data.dll
谢谢你,希望你能给我回复!
代码如下:
Imports System.Data.SqlClient
Imports System.IO
Public Class Form5
Dim connection As New SqlConnection("Server=kohyoung-aoi\sa; Database = testDB; Integrated Security = true")
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim command As New SqlCommand("insert into Table_Image1 (Name, Description, Barrowed, Returned, Picture) values (@Name, @Description, @Barrowed, @Returned, @Picture)", connection)
Dim ms As New MemoryStream
PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
command.Parameters.Add("@Name", SqlDbType.VarChar).Value = Txt1.Text
command.Parameters.Add("@Description", SqlDbType.VarChar).Value = Txt2.Text
command.Parameters.Add("@Barrowed", SqlDbType.VarChar).Value = txt3.Text
command.Parameters.Add("@Returned", SqlDbType.VarChar).Value = txt4.Text
command.Parameters.Add("@Picture", SqlDbType.Image).Value = ms.ToArray()
connection.Open()
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("Image Inserted")
Else
MessageBox.Show("Image not Inserted")
End If
End Sub
我希望它能在正常条件下运行,并且输出是将所有图像保存到SQL Server中。