English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

1 answers

Do you mean a Database Table or something else.

In a Database Table it's simple

Dim arrFilename() As String = Split(lblFilePath.Text, "\")
Array.Reverse(arrFilename)
Dim ms As New MemoryStream()
PictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat)
Dim arrImage() As Byte = ms.GetBuffer
ms.Close()
Dim frmStatusMessage As New frmStatus()
If Not didPreviouslyConnect Then
frmStatusMessage.Show("Connecting to SQL Server")
End If
Dim isConnecting As Boolean = True
While isConnecting

Try
Dim mConnection As New SqlConnection(connectionString)
Dim strSQL As String = _
"INSERT INTO Picture (Filename, Picture)" & _
"VALUES (@Filename, @Picture)"
Dim cmd As New SqlCommand(strSQL, mConnection)
With cmd
.Parameters.Add(New SqlParameter("@Filename", _
SqlDbType.NVarChar, 50)).Value = arrFilename(0)
.Parameters.Add(New SqlParameter("@Picture", _
SqlDbType.Image)).Value = arrImage
End With
mConnection.Open()
cmd.ExecuteNonQuery()
mConnection.Close()
isConnecting = False
didPreviouslyConnect = True
frmStatusMessage.Close()
MessageBox.Show(arrFilename(0) & " saved to the database.", _
"Image Save Status", MessageBoxButtons.OK, _
MessageBoxIcon.Information)

Catch sqlExc As SqlException
MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit While
Catch exc As Exception
If connectionString = SQL_CONNECTION_STRING Then
connectionString = MSDE_CONNECTION_STRING
frmStatusMessage.Show("Connecting to MSDE")
Else
frmStatusMessage.Close()
MessageBox.Show(CONNECTION_ERROR_MSG, _
"Connection Failed!", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End
End If
End Try
End While

Helmut

2006-07-12 00:10:31 · answer #1 · answered by hswes 2 · 0 0

fedest.com, questions and answers