Viewing Records in a listbox

Discussion in 'Visual Basic ( VB )' started by bouki, Mar 4, 2011.

  1. bouki

    bouki New Member

    Joined:
    Apr 9, 2010
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice