1 Attachment(s)
How to get values from listview and display it to textbox using sql database ?
Attachment 99997
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
Re: How to get values from listview and display it to textbox using sql database ?
Erm ... not making a lot of sense there. Where do the listview (is it actually a listview?) entries come from in the first place? Where are they going to and why? Why are you using textboxes as receivers rather than transmitters of data? What have you done so far, apart from creating the form?
Re: How to get values from listview and display it to textbox using sql database ?
Quote:
Originally Posted by
dunfiddlin
Erm ... not making a lot of sense there. Where do the listview (is it actually a listview?) entries come from in the first place? Where are they going to and why? Why are you using textboxes as receivers rather than transmitters of data? What have you done so far, apart from creating the form?
Code:
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 ?
Re: How to get values from listview and display it to textbox using sql database ?
Look at your code:
Code:
While rdr.Read
AddTXT.Text = rdr("Stock")
End While
You are resetting the Text value to the next item until the While loop is finished. Thus, logically, only the last value will be held in that property's backing value. :)
Re: How to get values from listview and display it to textbox using sql database ?
Quote:
Originally Posted by
AceInfinity
Look at your code:
Code:
While rdr.Read
AddTXT.Text = rdr("Stock")
End While
You are resetting the Text value to the next item until the While loop is finished. Thus, logically, only the last value will be held in that property's backing value. :)
im a newbie here..so what to do ? how can i display it in the right way ? :(
Re: How to get values from listview and display it to textbox using sql database ?
So? We were all newbies once. If you can't be bothered to read the documantation then at least scroll through the suggestions made by the IDE when you type in AddTXT. where you'll find a fairly obviously appropriate method amongst the first page of A's!
Re: How to get values from listview and display it to textbox using sql database ?
If you're using a TextBox, there's only one way you can display all the data without setting the MultiLine property to true for that control--use delimeters for each piece of data. So you would append to the Text with one value, add a comma, and next time around, add another bit of the data. Otherwise add to a collection and use String.Join() to avoid having to check for the last element or having to remove the last comma or whatever at the end...
Otherwise, you'll be writing each piece of data on a newline. When you just use the plain assignment operator, you are replacing the existing data in the textbox with another string value. So you're definitely not going to have all of the data there by the last time you assign a value to this property. Depending on how large the data is too, you may want to consider a StringBuilder before you abuse "+=".
I still don't get what you're expecting to happen though. You need to clarify that in more detail. I see in the image "Brand" and "Description", which would indicate to me that these are single values. So perhaps you are trying to loop through a data collection for a single value? I don't understand how you want a bunch of data to fit in those (single line?) textboxes... And especially for the overall size of those controls. There's not a lot of "view" space there...
~Ace