نحوه ذخیره عکس در sql توسط برنامه نویسی ویژوال بیسیک
در جنرال : Imports System.IO
در داخل Form_load
Dim Cnn As New SqlClient.SqlConnection
Dim Comm As New SqlClient.SqlCommand
Cnn.ConnectionString = "Server=(local);Database=database_name;Trusted_Connection=True;"
Cnn.Open()
Comm.Connection = Cnn
Comm.CommandType = CommandType.Text
Dim stream As New FileStream(My.Application.Info.DirectoryPath & "\pic_name.JPG", FileMode.Open)
Dim reader As New BinaryReader(stream)
Dim imgByte() As Byte
imgByte = reader.ReadBytes(stream.Length)
Dim strSQL As String
strSQL = "INSERT INTO table_name(field_name) VALUES (@Picture)"
Comm.Parameters.Add("@Picture", imgByte)
Comm.CommandText = strSQL
Comm.ExecuteNonQuery()
stream.Close()
ادامه مطلب ...