1.11M Members

How to get values from listview and display it to textbox using sql databas

 
0
 

How to get values from listview and display it to textbox using sql database ?
and then i can update the items in listview using a button..then refresh the listview
after i click the button...

tnx for the help in advance..im just a newbie in vb.net 0da2d193278007986792bf92e19433ab

Attachments
 
0
 

Post your code. how far you doing this.

This following code to get items on listview and show it in textboxes

Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
    Dim x As Integer = CInt(ListView1.SelectedItems(0).Index)

    TextBox1.Text = ListView1.Items(x).SubItems(0).Text
    TextBox2.Text = ListView1.Items(x).SubItems(1).Text
End Sub
 
0
 

in my other form i did the saving thing from textbox to database..and retrieve the data throught listview..now what i want is..to get that items from listview and display it to texbox and can update the data by clicking the button and refreshes the listview which i can't get through cause i dont know what to do...

 
0
 

I was give you the answer about getting items on listview in previous post.
How about post your update code?

 
0
 
If ListView1.SelectedItems.Count > 0 Then
            conn.Open()
            With com
                .Connection = conn
                .CommandText = "SELECT * FROM ItemTBL "
                .CommandType = CommandType.Text
            End With
            rdr = com.ExecuteReader
            While rdr.Read
                AddTXT.Text = rdr("Stock")
            End While
            rdr.Close()
            conn.Close()

thats my code..i did manage to click an item from listview in display it to textbox but my problem is...it only displays the last record...why is that ?

 
0
 

but my problem is...it only displays the last record...why is that ?

Actualy, your code show the entire data but it will show you the last record because you use textbox to show it. Textbox value will replace with current record in looping and the end it will replace with last record.
If you change the line 10 with combobox (Combobox1.Items.Add (rdr("Stock")) then you will see the entire records.

But why you bind it again to database if you just want to display the selected item on listview?
Just use the code that i give to you above..
After you fill listview with data from database then use this following code to show selected item on listview.

Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
    Dim x As Integer = CInt(ListView1.SelectedItems(0).Index)

    TextBox1.Text = ListView1.Items(x).SubItems(0).Text
    TextBox2.Text = ListView1.Items(x).SubItems(1).Text
End Sub
 
0
 

i need to create a project using vb.net and sql as the server
in my project i have th buttons save, edit, delite, and view.
add button to add the data inputed in the textboxes to the database
view to show the data in the database to my listview
edit to edit data delete to delete data
to edit and delete i need to select the data in the listview and put it back to the text boxes
can someone give me some codes i am new in programming and it is very difficult to find usefull codes thank you very much

You
Post:
Start New Discussion
View similar articles that have also been tagged: