hiiii..i am using asp.net 2005 in VB language and sqlserver 2005..in my form i am using 2 dropdownlist boxes..if i select a name in the dropdown list box1 then the corresponding last name is selected in the dropdwon listbox2...till now everything is working fine,,,now if i want to change the lastname(tht means select different surname for tht name)and press update button it doesnot get updated....,,,,how do i achieve ths,,,
in short i want to update dropdown list box 2 with the new selected item for the corresponding name in dropdown listbox1..
pls help,,,reply asap,,
thnks in advance

Can you tell me how you are trying to approach this in the first place before I suggest anything ?

code on submit button>>>>

 If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If

        If (DropDownList1.SelectedValue.Equals("Standard")) Then
            st = "Menu_Standard"
        Else
            st = "Menu_User"
        End If
        Dim str10 As String

        str10 = "select SUB_ID from " & st & " where ID=" & DropDownList2.SelectedValue
        cmd = New SqlCommand(str10, conn)
        da = cmd.ExecuteReader
        Dim ramram As Integer
        If da.Read = True Then

            If (da.Item("SUB_ID").ToString = "") Then
                ramram = 0
            Else
                ramram = da.Item("SUB_ID").ToString
            End If
        End If
        da.Close()

        Dim myName As String = ""
        If ramram = 0 Then

            myName = ""
            str10 = ""
        Else
            str10 = "select MENU_NAME from " & st & " where ID=" & ramram
            cmd = New SqlCommand(str10, conn)
            da = cmd.ExecuteReader

            If da.Read = True Then
                myName = da.Item("MENU_NAME").ToString
            End If
            da.Close()
        End If

        str10 = "update " & st & " set"

        If TextBox4.Text = "" Then
        Else
            str10 = str10 & " MENU_NAME='" & TextBox4.Text & "',"
        End If


        If CheckBox1.Checked Then
            str10 = str10 & " NODE='True',"
        Else
            str10 = str10 & " NODE='False', LINK='" & TextBox2.Text & "', QUERY='" & TextBox3.Text & "',"
        End If

        If TextBox1.Text = "" Then
            str10 = str10 & " DESCRIPTION=''"

        Else
            str10 = str10 & " DESCRIPTION='" & TextBox1.Text & "'"

        End If

        If myName = DropDownList3.SelectedItem.Text Then
            str10 = str10 & ", SUB_ID=" & DropDownList3.SelectedValue
            MsgBox(str10)
        End If

        str10 = str10 & " where MENU_NAME='" & DropDownList2.SelectedItem.Text & "'"
        MsgBox(str10)
        cmd = New SqlCommand(str10, conn)
        Try

            da = cmd.ExecuteReader

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
        da.Close()

        conn.Close()

do i need to paste my whole code

hi bala here is ma code

Edited 3 Years Ago by Dani: Formatting fixed

MsgBox(str10)
cmd = New SqlCommand(str10, conn)
Try

da = cmd.ExecuteReader

Just curious..

Why are you calling an ExecuteReader with an update query?
Shouldn't you be using an ExecuteNonQuery instead?

Just curious..

Why are you calling an ExecuteReader with an update query?
Shouldn't you be using an ExecuteNonQuery instead?

dude it doesnt take da withexecute non reader

ne idea how to do it

Sorry didn't get you.
But let me clarify myself.

When you use a command object to update or insert in a database, you need to use an Executenonquery.

Maybe this is giving the problem.

So try

da = cmd.ExecuteNonQuery

in the end where you are trying to update the table instead of using ExecuteReader.

fine,,let me clear maslf 1ce again....in detail
i have 3 dropdownlist in ma page,,ok,,on selecting a value frm 1st dropdownlist,,dropdownlist 2 gets updated with its corresponding value,,,now if i select a value from dropdownlist2 the corresponding value gets selected in dropdownlist3.....till now all is working fine...now,,if i select a different value in dropdownlist3 and press the update button,i m not able to get the new value(i.e the new selected value)..hope u got ma problem

Yes ..I got it that far..

m not able to get the new value(i.e the new selected value)

So is it giving you any error while updating?
If yes, can you post that as well.

If no, well we 'll think of that part later.

Yes ..I got it that far..

So is it giving you any error while updating?
If yes, can you post that as well.

If no, well we 'll think of that part later.

no bala,,it is not giving any kind of error,,,i am not able to get the new value of dropdownlist3,,,let me clarify 1ce again if u still didnt get it,,let me kno,,thnks in advance

Well I understood your problem buddy.

OK. One more try.
Try this.
In your code that you posted, your variable ramram has been declared as integer and you are using the statement.

ramram = da.Item("SUB_ID").ToString

Try using an Integer.Parse instead.
This might work.

This article has been dead for over six months. Start a new discussion instead.