Thursday, April 29, 2010

store photo to sql server database


Database to store the photo:-

Table:-actors

Front end:-

Methods to use:-

a. Register "photo.dll".(Click Here to Download Photo.dll. After downloading extract it)

b. Design database.

c. Design front end.

d. Write code as below.

Codes:-

Dim cnph As New ADODB.Connection 'connection variable

Dim rsph As New ADODB.Recordset 'recordset for text box and photo

Dim phg As New getsaveph 'for photoget

Dim fn As String 'file name variable for common dialog

Private Sub Form_Load() 'connection

With cnph

.Provider = "sqloledb.1"

.ConnectionString = "user id=sa;data source=cseclass;initial catalog=kaliwood"

.Open

End With

End Sub

Private Sub cmdbrowse_Click() 'browse picture

cdimg.ShowOpen

fn = cdimg.FileName

imgpic.Picture = LoadPicture(fn)

End Sub

Private Sub cmdedit_Click() 'updating with picturepicture

rsph.Update

rsph.Fields(0) = txtaid.Text

rsph.Fields(1) = txtname.Text

rsph.Fields(2) = txtdob.Text

rsph.Fields(3) = txtcontact.Text

phg.SavePicDb rsph, 4, fn

MsgBox "data are updated"

End Sub

Private Sub cmdfirst_Click() 'movefirst

rsph.MoveFirst

Call dataget

End Sub

Private Sub cmdlast_Click() 'move last

rsph.MoveLast

Call dataget

End Sub

Private Sub cmdnews_Click() 'make blank for new

txtaid.Text = ""

txtname.Text = ""

txtdob.Text = ""

txtcontact.Text = ""

End Sub

Private Sub cmdopen_Click() 'open data from database

If rsph.State = 1 Then rsph.Close

rsph.Open "select * from actors", cnph, adOpenDynamic, adLockPessimistic

Call dataget

End Sub

Sub dataget() 'data getting from the database in the frontend

txtaid.Text = rsph.Fields(0)

txtname.Text = rsph.Fields(1)

txtdob.Text = rsph.Fields(2)

txtcontact.Text = rsph.Fields(3)

imgpic.Picture = LoadPicture(phg.GetPicFromDb(rsph, 4))

End Sub

Private Sub cmdsaves_Click() 'saving data into the data base

rsph.AddNew

Call datassave

phg.SavePicDb rsph, 4, fn

MsgBox "saved"

End Sub

Sub datassave() 'saving data

rsph.Fields(0) = txtaid.Text

rsph.Fields(1) = txtname.Text

rsph.Fields(2) = txtdob.Text

rsph.Fields(3) = txtcontact.Text

End Sub

Private Sub Command6_Click() 'moving data next

rsph.MoveNext

If rsph.EOF = True Then

MsgBox "not found"

rsph.MoveLast

Else

Call dataget

End If

End Sub

Private Sub Command7_Click() 'moving data previously

rsph.MovePrevious

If rsph.BOF = True Then

MsgBox "sorry"

rsph.MoveFirst

Else

Call dataget

End If

End Sub


For Further Reading,
Software Developing

0 comments:

Post a Comment

 

Popular Posts

Man Behind This Blog