|
-
Apr 4th, 2004, 04:15 PM
#1
Thread Starter
Fanatic Member
Pulling sql data. Need to update txtbox based on dropdownlist
I've configured my connection. My adapter pulls two columns from a SQL table;VENDORID and VENDNAME. I binded it to a dropdownlist, so it will show the contents of the VENDORID column in the dropdownlist on page load. Now I need to change the text of a textbox based on the selected item in the dropdown list. So whichever VENDORID is selected in the drop-down list, i need the text to change to the VENDORNAME that is on the same row in sql. Can I use the same adapter? I'm not sure how to do this.
I tried using a sqlcommand that runs a query select VENDNAME from PM00200 where VENDID='value thats selected' and storing it in a variable. But it gives me problems with my string. Here's the code:
Private Sub ddlVendorID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlVendorID.SelectedIndexChanged
Dim conn As New SqlClient.SqlConnection()
Dim comm As New SqlClient.SqlCommand()
Dim vname As String
With conn
.ConnectionString = "server=HAL/SBMTWO;uid=sa;password=sapass;initial catalog=SBM01"
End With
With comm
.CommandType = CommandType.Text
.CommandText = "select vendname from pm00200 where VENDORID='" + ddlVendorID.SelectedItem.Value.ToString + "'"
End With
conn.Open()
comm.ExecuteReader()
vname = comm.ToString
txtVendorName.Text = vname.ToString
End Sub
I don't get any errors, but the values don't carry to the textbox on selectedindexchange.
Anyway around this?
Thanks!
-
Apr 4th, 2004, 04:28 PM
#2
Frenzied Member
I had a similar situation where I had to link a name with an id. I created a class that consted of two properties, name and ID. I looped through the database and created a new object for each row. a combo box lists the id's and when it's time to link them back together, I simply parsed the id from the combo box text and used the object to grab the name
when the object's ID property was, for example, 002, the name was in the objects name property.
That may not me practical if you have a hundred or more rows but that's one way of doing it.
-
Apr 4th, 2004, 04:32 PM
#3
Thread Starter
Fanatic Member
Yea I only have 2 columns i'm pulling, one fills the dropdown list, the other will have the value of the next column, based on the ddl.
I'm very new at VB.NET, so alot of what you just said doesn't mean much at the moment.
But i have gotten this thing to pull and write to the database, do a validation thing.
-
Apr 4th, 2004, 04:45 PM
#4
Frenzied Member
about how many records are there going to be? Or, is it one of those situation where it may grow beyond what you anticipate initially?
I'm looking at my code right now and am wondering if I might try what you did...simply do a query whenever the 'selectedIndex' changes on one control and populate the next. I wonder if ado connection/query would be more efficient as compared to the memory allocation used for the objects? maybe one of the vets here can give an opinion.
-
Apr 4th, 2004, 04:57 PM
#5
Thread Starter
Fanatic Member
Well its pulling records from another database, it won't be adding to it or anything, there's less than 100
The way i did it, is the only way i could think of, even though I am a beginner.
the code is in place, and there are no errors, it just won't pull the data into the textbox
-
Apr 4th, 2004, 10:53 PM
#6
Frenzied Member
hmm...post your code and let us see what you have.
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
|