0

Help please -I am still learning Visual Web Developer in VB.Net code
Sorry to ask, there is probably an easy fix or I have this completely wrong.

I have a DropDownList2 (CustName) and a TextBox16 (for CustID)
I want the command to look at the SQL Table and fill the TextBox with the matching CustID for the CustName
when the CustName is selected in the DropDownList

When I run the page, I am getting no errors. I select the item in the DropDownList the AutoPostBack refreshes the page but the textbox remains empty.

ReachoutCust is the SQL Table
CustID And CustName are Fields within the table

  Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList2.SelectedIndexChanged

        Dim cmd As New SqlCommand()
        Dim con As New SqlConnection()
        con = New SqlConnection("Data Source=[SERVER NAME];Initial Catalog=[SQL DATABASE NAME];Integrated Security=True")

        con.Open()

        cmd = New SqlCommand("SELECT CustID FROM ReachoutCust WHERE CustName = 'DropDownList2.Text'", con)
        dr = cmd.ExecuteReader
        While dr.Read
         TextBox16.Text = dr(0).ToString()

     End While
        dr.Close()

    End Sub
3
Contributors
7
Replies
10
Views
5 Years
Discussion Span
Last Post by JorgeM
0

Here's mine. Still as you wish. I'm here trying to find out how to produce a link instead of the textbox. Any help would be cool, but this definitely works to do what you want:

<script type="text/javascript">
function fifa()
{
    var frm = document.forms[0];
    var abc = frm.browsers.value;
    if (abc === "A")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I212JNW9WR139D70085E3/ical.ics";
    else if (abc === "B")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I21263C4FA139C15D7BAC/ical.ics";
    else if (abc === "C")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I212WPEPUP1396F85E02B/ical.ics";
    else if (abc === "D")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I212NEKA9Y139E57D8DDA/ical.ics";
    else if (abc === "E")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I212ETT9PK139C15F2C25/ical.ics";
    else if (abc === "F")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I212Y6WMF4139C1C22637/ical.ics";
    else if (abc === "G")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I212AT4NRY139C165DB97/ical.ics";
    else if (abc === "H")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I212XH7AWH139C160ED75/ical.ics";
    else if (abc === "I")
        frm.text1.value = "https://ical.bookeo.com/20212KWWNLA1396F7FEA1BWFW3J6/LHRAKRK63FAMPJP6/Z/I2123X6H36139C1C1A4E5/ical.ics";

}
</script>

<center>
<form name="form1">
Subscribe to your calendar link:
<select id="browsers" onchange="fifa()">
<option value="0">- choose a tutor -</option>
<option value="A">Ashley C.</option>
<option value="B">Danielle C.</option>
<option value="C">Jon S.</option>
<option value="D">Mekenna M</option>
<option value="E">Norma C.</option>
<option value="F">Tyler K.</option>
<option value="G">Vanessa A.</option>
<option value="H">Veronica G</option>
<option value="I">William K.</option>
</select><br><br>

<textarea name="text1" style="width:400px; height:100px;">

</textarea>
</form>
0

I tried the suggestion: Try in line 16, dropdownlist2.selectedvalue
Still getting the same results. No errors but textbox is still not populating with the selected dropdownlsit item.

0

Sorry, i dont know why i referred to line 16. What I mean was update this line of your code:

cmd = New SqlCommand("SELECT CustID FROM ReachoutCust WHERE CustName = 'DropDownList2.SelectedValue'", con)

0

I just tested this out, and it works as expected...

Dim oConn As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("DB_NAME").ConnectionString)
Dim oCmd As New System.Data.SqlClient.SqlCommand
Dim oRdr As System.Data.IDataReader

oConn.Open()
oCmd.Connection = oConn
oCmd.CommandText = "Select CustID FROM ReachoutCust WHERE CustName = '" & DropDownList2.SelectedValue & "'"

oRdr = oCmd.ExecuteReader
While oRdr.Read()
   TextBox1.Text = oRdr(0).ToString()
End While
oRdr.Close()
oConn.Close()

Edited by JorgeM

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.