|
-
May 12th, 2013, 10:07 AM
#1
Thread Starter
Registered User
How to get values from listview and display it to textbox using sql database ?

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
-
May 12th, 2013, 11:59 AM
#2
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?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 12th, 2013, 07:42 PM
#3
Thread Starter
Registered User
Re: How to get values from listview and display it to textbox using sql database ?
 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 ?
-
May 12th, 2013, 08:44 PM
#4
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.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 12th, 2013, 09:46 PM
#5
Thread Starter
Registered User
Re: How to get values from listview and display it to textbox using sql database ?
 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 ?
-
May 13th, 2013, 12:04 PM
#6
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!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 13th, 2013, 04:21 PM
#7
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
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|