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

Recommended Answers

All 5 Replies

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
    
    rs.MoveNext
    Loop
    
    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
    Else
        cmdPrintAll.Enabled = True
    End If
    
    Dbconn.Close
    
    Exit Sub
err:
    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:

http://www.vbtutor.net/lesson26.html


Hope this helps.

And please be more clean in stating (writing) your problem.

If you may.

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
server=db4free.net;Port=3306

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.