|
-
January 10th, 2013, 10:22 PM
#1
error in save and load image ms access
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'TODO: This line of code loads data into the 'StudDataSet.student' table. You can move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.StudDataSet.student)
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Extern Innovation\Desktop\stud.mdb")
con.Open()
adapter = New OleDbDataAdapter("select * from student", con)
ds = New DataSet()
adapter.Fill(ds, "student")
ds.Tables(0).Constraints.Add("pk_sno", ds.Tables(0).Columns(0), True)
TextBox1.Text = ds.Tables(0).Rows(rno)(0).ToString()
TextBox2.Text = ds.Tables(0).Rows(rno)(1).ToString()
TextBox3.Text = ds.Tables(0).Rows(rno)(2).ToString()
'PictureBox1.Image = Nothing
' If (ds.Tables(0).Rows(rno)(3)!System.DBNull.Value) Then
'photo_array = ds.Tables(0).Rows(rno)(3).ToString
' ms = New MemoryStream(photo_array)
'PictureBox1.Image = Image.FromStream(ms)
' End If
con.Close()
End Sub
Private Sub browseButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles browseButton.Click
Dim res As DialogResult
OpenFileDialog1.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*"
res = OpenFileDialog1.ShowDialog()
If (res = DialogResult.OK) Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
Private Sub insertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles insertButton.Click
Dim sno As Integer
Dim sname, course As String
Dim photo As Image
'Dim query As Integer
sno = TextBox1.Text
sname = TextBox3.Text
course = TextBox3.Text
photo = PictureBox1.Image
Dim ms As New MemoryStream
'Dim stream As FileStream
photo.Save(ms, ImageFormat.Jpeg)
Dim data = ms.ToArray()
ms.Close()
'con = New OleDbConnection("insert into student(sno,sname,course,photo) values(" + TextBox1.Text + ",'" + TextBox2.Text + "','" + TextBox3.Text + "',@photo)", con)
con.Open()
Dim str As String = "insert into student values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "','" & PictureBox1.ToString & "'"
Dim mycommand As New OleDbCommand
mycommand.Parameters.Add("@sno", OleDbType.VarChar)
mycommand.Parameters.Add("@sname", OleDbType.VarChar)
mycommand.Parameters.Add("@course", OleDbType.VarChar)
' mycommand.Parameters.Add("@photo", OleDbType.VarChar)
mycommand.Parameters("@sno").Value = sno
mycommand.Parameters("@sname").Value = sname
mycommand.Parameters("@course").Value = course
' mycommand.Parameters("@photo").Value = photo
mycommand.CommandText = Text
mycommand.Connection = con
'mycommand.ExecuteNonQuery()
cmd = New OleDbCommand(str, con)
cmd.Parameters.AddWithValue("@photo", photo)
Dim n As Integer
cmd.ExecuteNonQuery()
con.Close()
If (n > 0) Then
MessageBox.Show("record inserted")
' PictureBox1.Image = My.Resources.Culture.Equals
Else
MessageBox.Show("insertion failed")
End If
'Dim conv_photo As Convert
'If (PictureBox1.Image!DBNull.Value) Then
' Dim ms As MemoryStream = New MemoryStream()
' PictureBox1.Image.Save(ms, ImageFormat.Bmp)
' Dim photo_aray As Byte
'photo_aray = ms.Read(photo_aray, 0, 0)
'ms.Position = 0
' ms.Read(photo_aray, 0, 0)
' Dim data As IDataObject
' Dim bmap As Image
' Dim ms As New IO.MemoryStream()
'PictureBox1.Image.Save(ms, ImageFormat.Bmp)
'data = Clipboard.GetDataObject()
'If data Is Nothing Then Exit Sub
'If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
'photo = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
' photo.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
' Image = ms.GetBuffer
'cmd.Parameters.AddWithValue("@photo", photo)
'End If
End Sub
this codeing is save and load image in ms access but is not working so please correct this code .mdb file name stud tabale name is student fildname is photo fild type is olb object
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|