0
誰でも私をデータベースのmsアクセス2007に画像ボックスの画像を更新/編集する方法を教えていただけますか?このコードを使用してピクチャボックスからデータベース(MS Access2007)に画像を更新/保存する方法
イム:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myCommand As New OleDbCommand
Dim SQL As String
Dim ms As New System.IO.MemoryStream
Dim bmpImage As New Bitmap(PictureBox1.Image)
Try
If Not con.State = ConnectionState.Open Then Open_Koneksi()
SQL = "UPDATE tb_pegawai SET [email protected], [email protected]_lahir, [email protected], [email protected], [email protected], [email protected], [email protected] WHERE [email protected]"
myCommand.Parameters.AddWithValue("@nik", TextBox1.Text)
myCommand.Parameters.AddWithValue("@nama", TextBox2.Text)
myCommand.Parameters.AddWithValue("@tgl_lahir", DateTimePicker1.Text)
myCommand.Parameters.AddWithValue("@gender", jk.Text)
myCommand.Parameters.AddWithValue("@jabatan", ComboBox1.Text)
myCommand.Parameters.AddWithValue("@alamat", TextBox4.Text)
myCommand.Parameters.AddWithValue("@telepon", TextBox5.Text)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
bytImage = ms.ToArray()
ms.Close()
myCommand.Parameters.AddWithValue("@image", bytImage)
MsgBox("Data saved")
myCommand.Connection = con
myCommand.CommandText = SQL
myCommand.ExecuteNonQuery()
Data_Load()
con.Close()
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Button1.Enabled = False
Finally
con.Dispose()
End Try
End Sub
私はプログラムを実行すると、エラーか何かを取得できませんでした。 ただし、画像はmsアクセスで表示されません。
あなたの質問は間違っています。アクセスは、名前付きパラメータをそのまま使用します。パラメータは、クエリに表示される順序で追加する必要があります。あなたはAddWithValueではなくすべてのものに 'Add'を使うべきです – Plutonix
コードを書く方法の例を教えてもらえますか? – Madz
たとえば、 "@nik"はクエリの最後のパラメータであるため、最後に追加する必要があります。 – LarsTech