Hello all it's my first question
I am new to database with visual basic .... I am working on a application form that allow users to register log in and get a profile page .. the problem is i need a code of leting me printing data from the databse to my form ... by example on the registration page the user is asked his email .. his email is saved in my online databse .. how can i with code show the email in the form ?

Thanks :D

7 Years
Discussion Span
Last Post by AndreRet

You mean showing records from your Database to a form.?

Try using Listview.

Heres a sample:

Public Sub Init_Data()

'On Error GoTo err:

    If rs.State = adStateOpen Then rs.Close	
    lvlEmpInfo.ListItems.Clear			'lvlEmpinfo - name of the Listview

rs.Open "Select * from Tablename", Dbconn, adOpenKeyset, adLockPessimistic	'Dbconn is my Database connection

    Do While rs.EOF = False
    lvlEmpInfo.ListItems.Add , , rs.Fields("EmpID").Value		

    'Subitems(1), the (1) is the arrangement of columns from 
    'DOnt know if you have to start from 0 really
    'The ("Fields") is where you put the column name from your database
    lvlEmpInfo.ListItems(lvlEmpInfo.ListItems.Count).SubItems(1) = rs.Fields("Field1").Value
    lvlEmpInfo.ListItems(lvlEmpInfo.ListItems.Count).SubItems(2) = rs.Fields("Field2").Value
    lvlEmpInfo.ListItems(lvlEmpInfo.ListItems.Count).SubItems(3) = rs.Fields("Field3").Value
    If lvlEmpInfo.ListItems.Count = 0 Then		'Condition if there are no records from database
        cmdDelete.Enabled = False
        cmdEdit.Enabled = False
        cmdPrintSel.Enabled = False
        cmdPrintAll.Enabled = False
        cmdPrintAll.Enabled = True
    End If
    Exit Sub
    MsgBox err.Description, vbCritical, "Error"
    Set rs = Nothing
End Sub

You can then just call this sub in your form load event.

Private Sub Form_Load()

Call Init_Data  'You can just remove the 'Call' word, still the same
End Sub

Or you could use Datagrid:


Hope this helps.

Edited by abelingaw: n/a


What database are you using, access, MySql, Sql?

If you say online, on a local network or the web?

Do you have the IP for the server etc.?


What database are you using, access, MySql, Sql?

If you say online, on a local network or the web?

Do you have the IP for the server etc.?

I am using sql www.db4.net


Now we need to get the version of your sql. 2000, 2005, 2008? There is different connection strings for each version....

Have a look at THIS site for the correct connection string.

Once you are connected, you will be using the exact same code that you use for a normal desktop application.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.