|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to save and retrieve picture from database acess2003
Hi every i have following code when i want to execute the program i gives me runtime error 545Un able to bind field or data member"Picture" my table have three field one is Pubid and othe txtdecription which hold text and third one Picture which is type OLE to hold picture pub when i excute i get above error please help I m using office xp acess xp visual basic code:Option Explicit Private cn As ADODB.Connection Private rs As ADODB.Recordset Private Sub Command1_Click() 'making txtdescription show whats in the description field rs.Fields("Description") = txtDescription.Text rs.MovePrevious 'just to make sure your at the start and so you don't get that error. If rs.BOF Then rs.MoveFirst FillFields End Sub Private Sub Form_Load() Set cn = New ADODB.Connection 'make this the path to the image database. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source= C:\picdata.mdb" cn.Open 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\picdata.mdb;Persist Security Info=False Set rs = New ADODB.Recordset rs.Open "Table1", cn, adOpenKeyset, adLockPessimistic, adCmdTable FillFields 'this is a sub that I'll explain later. End Sub Private Sub cmdPrevious_Click() 'making txtdescription show whats in the description field rs.Fields("Description") = txtDescription.Text rs.MovePrevious 'just to make sure your at the start and so you don't get that error. If rs.BOF Then rs.MoveFirst FillFields End Sub Private Sub cmdNext_Click() 'making txtdescription show whats in the description field rs.Fields("Description") = txtDescription.Text rs.MoveNext If rs.EOF Then rs.MoveLast FillFields If rs.EOF Then MsgBox "At last record" 'avoiding that nasty error. End If End Sub Private Sub cmdDelete_Click() 'this will delete the entire record. If Not (rs.BOF And rs.EOF) Then rs.Delete If Not (rs.BOF And rs.EOF) Then rs.MoveNext If rs.EOF Then rs.MoveLast FillFields End If End If End Sub Private Sub cmdAdd_Click() Dim bytData() As Byte Dim strDescription As String On Error GoTo err With dlgAdd 'remember the common dialog box. 'filtering so only jpg's and gifs are shown! .Filter = "Picture Files (*.jpg, *.gif)|*.jpg;*.gif" .DialogTitle = "Select Picture" 'sets the title of it. .ShowOpen 'show the open dialog box. 'bit to "convert" the image to binary. Open .FileName For Binary As #1 ReDim bytData(FileLen(.FileName)) End With Get #1, , bytData Close #1 'show a input box to enter description to the description field. strDescription = InputBox("Enter description.", "New Picture") With rs .AddNew .Fields("Description") = strDescription 'adding record to db .Fields("Picture").AppendChunk bytData ' Here error occur adding the picture to the db.Update End With FillFields Exit Sub err: If err.Number = 32755 Then 'simple error check. Else MsgBox err.Description err.Clear End If End Sub Public Sub FillFields() If Not (rs.BOF And rs.EOF) Then txtDescription.Text = rs.Fields("Description") Set Image1.DataSource = rs 'setting image1's datasource Image1.DataField = "Picture" 'set its datafield. End If End Sub Private Sub Form_Unload(Cancel As Integer) On Error Resume Next rs.Close cn.Close Set rs = Nothing Set cn = Nothing 'closing all connections. End Sub |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > How to save and retrieve picture from database acess2003 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|