Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Viewing Records in a listbox (http://www.go4expert.com/forums/viewing-records-listbox-t25142/)

bouki 4Mar2011 10:40

Viewing Records in a listbox
 
I am trying to add the First Name of the members added in the database to be able to view them whenever i want to

Code:

Imports System.Data.SqlClient
Public Class adduser

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAddUser.Click
        Dim cn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim rdr As SqlDataReader

        cn.ConnectionString = " data source = Rayon\Rayon; Initial catalog = Library; uid=sa; password = minnie"

        cn.Open()

        cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Insert into Member (FName, MidName, LName, Street1, Street2, City, Zone, ContactHome, ContactWork, ContactCell, Email, Gender) values ('" & txtFname.Text & "', '" & txtMidName.Text & "' , '" & txtLname.Text & "', '" & txtStreet1.Text & "', '" & txtStreet2.Text & "' ,'" & txtCity.Text & "' ,'" & cbZone.Text & "' ,'" & txtHome.Text & "', '" & txtWork.Text & "' ,'" & txtCell.Text & "' ,'" & txtEmail.Text & "' ,'" & cbGender.Text & "' )"
        cmd.ExecuteNonQuery()

        cmd.CommandText = "select FName, LName from Member"
        rdr = cmd.ExecuteReader
        Do While rdr.Read
            Deleteuser.cbcvuser.Items.Add(rdr.Item("FName"))
        Loop

        cn.Close()




    End Sub

However when this is executed and a record is inserted, when i load the view form the first names are listed. If i close the view form(listbox) and reopen the values are gone.

I want to be able to view the members even without have to add a record


All times are GMT +5.5. The time now is 23:48.