error in save and load image ms access
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: error in save and load image ms access

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    6

    Exclamation 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
    Share on Google+

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: error in save and load image ms access

    Please use code tags so that we can read your code easier. It is explained here :

    http://forums.codeguru.com/showthrea...for-more-info)
    Share on Google+

  3. #3
    Join Date
    Oct 2012
    Posts
    6

    Re: error in save and load image ms access

    error for :number of query and desination filed are not in same.

    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim ray As String
    ray = Me.cjTextBox.Text
    Dim ray1 As String
    ray1 = Me.ptTextBox.Text
    Dim ans As String
    Dim company, flg2, address, branch, pt, desc, flg, lang, cj, email, path As String
    Dim amt As Integer



    Me.TextBox5.Text = Me.pathTextBox.Text
    Dim fs As New FileStream(TextBox5.Text, FileMode.Open, FileAccess.Read)
    Dim bys As New BinaryReader(fs)
    Dim bty(fs.Length) As Byte
    bys.Read(bty, 0, fs.Length)
    fs.Close()

    Me.FlgTextBox.Text = "adfcup"
    Me.Flg2TextBox.Text = "1"
    If Me.RadioButton1.Checked = True Then
    Me.LangTextBox.Text = "madrn"
    ElseIf Me.RadioButton2.Checked = True Then
    Me.LangTextBox.Text = "eng"
    End If


    Me.CompanyTextBox1.Text = Me.CompanyTextBox.Text
    Me.AddressTextBox1.Text = Me.AddressTextBox.Text
    Me.BranchTextBox1.Text = Me.BranchTextBox.Text
    Me.ComboBox1.Text = Me.PayeeTextBox1.Text

    company = CompanyTextBox1.Text
    address = AddressTextBox1.Text
    branch = BranchTextBox1.Text

    pt = PtTextBox.Text
    desc = DescTextBox.Text
    flg = FlgTextBox.Text
    flg2 = Flg2TextBox.Text
    lang = LangTextBox.Text

    cj = CjTextBox.Text
    path = TextBox5.Text


    If Me.ComboBox1.Text = Nothing Or Me.CjTextBox.Text = Nothing Or Me.PtTextBox.Text = Nothing Or Me.DescTextBox.Text = Nothing Then
    MsgBox("Please fill all field")

    ElseIf Len(Me.CjTextBox.Text) < 6 Then
    MsgBox("Please cj your cj number, should be 6 digit")
    Else


    con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\first projet\user\user\mycollege.mdb")
    con.Open()
    str = "insert into cj values('" & CompanyTextBox1.Text & "','" & AddressTextBox1.Text & "','",'" & DateTimePicker1.Value & "','" & CjTextBox.Text & "','" & PtTextBox.Text & "','" & DescTextBox.Text & "','" & FlgTextBox.Text & "','" & LangTextBox.Text & "',@logo,'" & Flg2TextBox.Text & "')"
    cmd = New OleDbCommand(str, con)
    cmd.Parameters.Add("company", OleDbType.VarChar).Value = CompanyTextBox1.Text
    cmd.Parameters.Add("address", OleDbType.VarChar).Value = AddressTextBox1.Text
    cmd.Parameters.Add("date", OleDbType.Date).Value = DateTimePicker1.Text
    cmd.Parameters.Add("cj", OleDbType.VarChar).Value = CjTextBox.Text
    cmd.Parameters.Add("pt", OleDbType.VarChar).Value = PtTextBox.Text
    cmd.Parameters.Add("desc", OleDbType.VarChar).Value = DescTextBox.Text
    cmd.Parameters.Add("flg", OleDbType.VarChar).Value = FlgTextBox.Text
    cmd.Parameters.Add("lang", OleDbType.VarChar).Value = LangTextBox.Text
    cmd.Parameters.Add("path", OleDbType.VarChar).Value = TextBox5.Text
    cmd.Parameters.AddWithValue("@logo", bty)
    cmd.ExecuteNonQuery()


    ' Me.CompanyTextBox1.Text = Form2.CompanyTextBox.Text
    'Me.AddressTextBox1.Text = Form2.AddressTextBox.Text


    Me.CompanyTextBox2.Text = Me.CompanyTextBox.Text
    Me.AddressTextBox2.Text = Me.AddressTextBox.Text

    Me.DateTextBox.Text = Me.DateTimePicker1.Text


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''TO SAVE NUMBER'''''''''''''''''''''''''''''''''''''''''

    ans = Val(ray) + Val(1)
    If Len(ans) = 1 Then
    Me.NumberTextBox.Text = "00000" & ans
    ElseIf Len(ans) = 2 Then
    Me.NumberTextBox.Text = "0000" & ans
    ElseIf Len(ans) = 3 Then
    Me.NumberTextBox.Text = "000" & ans
    ElseIf Len(ans) = 4 Then
    Me.NumberTextBox.Text = "00" & ans
    ElseIf Len(ans) = 5 Then
    Me.NumberTextBox.Text = "0" & ans
    ElseIf Len(ans) = 6 Then
    Me.NumberTextBox.Text = ans
    End If
    ans = Val(ray) + Val(1)
    If Len(ans) = 1 Then
    Me.numberTextBox1.Text = "00000" & ans
    ElseIf Len(ans) = 2 Then
    Me.numberTextBox1.Text = "0000" & ans
    ElseIf Len(ans) = 3 Then
    Me.numberTextBox1.Text = "000" & ans
    ElseIf Len(ans) = 4 Then
    Me.numberTextBox1.Text = "00" & ans
    ElseIf Len(ans) = 5 Then
    Me.numberTextBox1.Text = "0" & ans
    ElseIf Len(ans) = 6 Then
    Me.numberTextBox1.Text = ans
    End If
    Me.Validate()
    Me.cjnoBindingSource.EndEdit()
    Me.CjnoTableAdapter.Update(Me.CjnoDataSet.cjno)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Me.BindingNavigatorSaveItem.PerformClick()
    Me.BindingNavigator1.AddNewItem.PerformClick()
    Me.Validate()
    Me.cjBindingSource.EndEdit()
    Me.CjTableAdapter.Update(Me.CjDataSet.chq)
    Me.cjBindingSource.AddNew()
    Me.Label13.Text = Nothing
    Me.Label14.Text = Nothing
    Me.Label15.Text = Nothing
    Me.Label16.Text = Nothing
    Me.CjTextBox.Text = Me.NumberTextBox.Text
    Me.ptTextBox.Text = Me.numberTextBox1.Text
    Me.ComboBox1.Text = Nothing
    Me.ComboBox1.Select()
    End If '
    End Sub

    -----------------------------------
    Any idea how to solve this ?
    Share on Google+

  4. #4
    Join Date
    Oct 2012
    Posts
    6

    Question number of query and desination filed are not in same.

    [QUOTE=manikandan75;2101513]error for :number of query and desination filed are not in same.

    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim ray As String
    ray = Me.cjTextBox.Text
    Dim ray1 As String
    ray1 = Me.ptTextBox.Text
    Dim ans As String
    Dim company, flg2, address, branch, pt, desc, flg, lang, cj, email, path As String
    Dim amt As Integer



    Me.TextBox5.Text = Me.pathTextBox.Text
    Dim fs As New FileStream(TextBox5.Text, FileMode.Open, FileAccess.Read)
    Dim bys As New BinaryReader(fs)
    Dim bty(fs.Length) As Byte
    bys.Read(bty, 0, fs.Length)
    fs.Close()

    Me.FlgTextBox.Text = "adfcup"
    Me.Flg2TextBox.Text = "1"
    If Me.RadioButton1.Checked = True Then
    Me.LangTextBox.Text = "madrn"
    ElseIf Me.RadioButton2.Checked = True Then
    Me.LangTextBox.Text = "eng"
    End If


    Me.CompanyTextBox1.Text = Me.CompanyTextBox.Text
    Me.AddressTextBox1.Text = Me.AddressTextBox.Text
    Me.BranchTextBox1.Text = Me.BranchTextBox.Text
    Me.ComboBox1.Text = Me.PayeeTextBox1.Text

    company = CompanyTextBox1.Text
    address = AddressTextBox1.Text
    branch = BranchTextBox1.Text

    pt = PtTextBox.Text
    desc = DescTextBox.Text
    flg = FlgTextBox.Text
    flg2 = Flg2TextBox.Text
    lang = LangTextBox.Text

    cj = CjTextBox.Text
    path = TextBox5.Text


    If Me.ComboBox1.Text = Nothing Or Me.CjTextBox.Text = Nothing Or Me.PtTextBox.Text = Nothing Or Me.DescTextBox.Text = Nothing Then
    MsgBox("Please fill all field")

    ElseIf Len(Me.CjTextBox.Text) < 6 Then
    MsgBox("Please cj your cj number, should be 6 digit")
    Else


    con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\first projet\user\user\mycollege.mdb")
    con.Open()
    str = "insert into cj values('" & CompanyTextBox1.Text & "','" & AddressTextBox1.Text & "','",'" & DateTimePicker1.Value & "','" & CjTextBox.Text & "','" & PtTextBox.Text & "','" & DescTextBox.Text & "','" & FlgTextBox.Text & "','" & LangTextBox.Text & "',@logo,'" & Flg2TextBox.Text & "')"
    cmd = New OleDbCommand(str, con)
    cmd.Parameters.Add("company", OleDbType.VarChar).Value = CompanyTextBox1.Text
    cmd.Parameters.Add("address", OleDbType.VarChar).Value = AddressTextBox1.Text
    cmd.Parameters.Add("date", OleDbType.Date).Value = DateTimePicker1.Text
    cmd.Parameters.Add("cj", OleDbType.VarChar).Value = CjTextBox.Text
    cmd.Parameters.Add("pt", OleDbType.VarChar).Value = PtTextBox.Text
    cmd.Parameters.Add("desc", OleDbType.VarChar).Value = DescTextBox.Text
    cmd.Parameters.Add("flg", OleDbType.VarChar).Value = FlgTextBox.Text
    cmd.Parameters.Add("lang", OleDbType.VarChar).Value = LangTextBox.Text
    cmd.Parameters.Add("path", OleDbType.VarChar).Value = TextBox5.Text
    cmd.Parameters.AddWithValue("@logo", bty)
    cmd.ExecuteNonQuery()


    ' Me.CompanyTextBox1.Text = Form2.CompanyTextBox.Text
    'Me.AddressTextBox1.Text = Form2.AddressTextBox.Text


    Me.CompanyTextBox2.Text = Me.CompanyTextBox.Text
    Me.AddressTextBox2.Text = Me.AddressTextBox.Text

    Me.DateTextBox.Text = Me.DateTimePicker1.Text


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''TO SAVE NUMBER'''''''''''''''''''''''''''''''''''''''''

    ans = Val(ray) + Val(1)
    If Len(ans) = 1 Then
    Me.NumberTextBox.Text = "00000" & ans
    ElseIf Len(ans) = 2 Then
    Me.NumberTextBox.Text = "0000" & ans
    ElseIf Len(ans) = 3 Then
    Me.NumberTextBox.Text = "000" & ans
    ElseIf Len(ans) = 4 Then
    Me.NumberTextBox.Text = "00" & ans
    ElseIf Len(ans) = 5 Then
    Me.NumberTextBox.Text = "0" & ans
    ElseIf Len(ans) = 6 Then
    Me.NumberTextBox.Text = ans
    End If
    ans = Val(ray) + Val(1)
    If Len(ans) = 1 Then
    Me.numberTextBox1.Text = "00000" & ans
    ElseIf Len(ans) = 2 Then
    Me.numberTextBox1.Text = "0000" & ans
    ElseIf Len(ans) = 3 Then
    Me.numberTextBox1.Text = "000" & ans
    ElseIf Len(ans) = 4 Then
    Me.numberTextBox1.Text = "00" & ans
    ElseIf Len(ans) = 5 Then
    Me.numberTextBox1.Text = "0" & ans
    ElseIf Len(ans) = 6 Then
    Me.numberTextBox1.Text = ans
    End If
    Me.Validate()
    Me.cjnoBindingSource.EndEdit()
    Me.CjnoTableAdapter.Update(Me.CjnoDataSet.cjno)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Me.BindingNavigatorSaveItem.PerformClick()
    Me.BindingNavigator1.AddNewItem.PerformClick()
    Me.Validate()
    Me.cjBindingSource.EndEdit()
    Me.CjTableAdapter.Update(Me.CjDataSet.chq)
    Me.cjBindingSource.AddNew()
    Me.Label13.Text = Nothing
    Me.Label14.Text = Nothing
    Me.Label15.Text = Nothing
    Me.Label16.Text = Nothing
    Me.CjTextBox.Text = Me.NumberTextBox.Text
    Me.ptTextBox.Text = Me.numberTextBox1.Text
    Me.ComboBox1.Text = Nothing
    Me.ComboBox1.Select()
    End If '
    End Sub

    -----------------------------------
    Any idea how to solve this ?
    Share on Google+

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: error in save and load image ms access

    Not unless you can FORMAT YOUR CODE as described above. Also, delete duplicates.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!
    Share on Google+

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: error in save and load image ms access

    I am closing this thread now, as you got no intention of formatting your code properly. start a new thread with propet code tags, as i've described in post #2.

    Like it, don't like it - you expect help, we expect common curtosy.

    Hannes
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center