User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,269 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,440 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1233 | Replies: 0 | Solved
Reply
Join Date: Mar 2007
Posts: 34
Reputation: shy_wani is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
shy_wani shy_wani is offline Offline
Light Poster

update problem...

  #1  
May 5th, 2007
hi..
i wonder, what is wrong with my code? i want to let user update their previous question based on question number they selected.
i have a dropdownlist called qnum. when the qnum index changed, it should load respective question to textbox question.
however, i don't manage to update in the database as the updated question only appear in the page but the question was not being updated in the database.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            butDelete.Attributes.Add("onclick", "return confirm_delete();")
            sqlConn.Open()
            Dim surveyID As String = Request.QueryString("SurveyID")
            Dim queryString As String = "SELECT * FROM Survey Where SurveyID='" & surveyID & "';SELECT * FROM Question WHERE SurveyID='" & surveyID & "'"
            Dim sqlCommand As SqlCommand = New SqlCommand(queryString, sqlConn)
            Dim dataReader As SqlDataReader = sqlCommand.ExecuteReader()
            While dataReader.Read
                title.Text = dataReader("SurveyTitle").ToString
                description.Text = dataReader("SurveyDescription").ToString
            End While
            dataReader.NextResult()
            While dataReader.Read
                With qnum
                    .DataSource = dataReader
                    .DataTextField = "QuestionNum"
                    .DataValueField = "QuestionID"
                    .AutoPostBack = True
                    .DataBind()
                End With
            End While
            dataReader.Close()
            sqlConn.Close()
        End If
    End Sub

    Protected Sub qid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ConnDb(qnum.SelectedItem.Value)
    End Sub

    Protected Sub ConnDb(ByVal qnum As String)
        Dim surveyID As String = Request.QueryString("SurveyID")
        Session("sSurveyID") = surveyID
        sqlConn.Open()
        Dim viewAll As String = "SELECT * FROM Question Where SurveyID='" & surveyID & "' AND QuestionID='" & qnum & "'" 'AND QuestionID=qnum.SelectedValue
        Dim sqlviewAll As SqlCommand = New SqlCommand(viewAll, sqlConn)
        Dim read As SqlDataReader
        read = sqlviewAll.ExecuteReader()
        While read.Read
            question.Text = read("Question").ToString
        End While
        read.Close()
        sqlConn.Close()
    End Sub

    Private Sub butSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSave.Click
        Try
            Dim strqnum As String = qnum.SelectedItem.Value
            Dim strquestion As String = question.Text.Trim

            Dim sql As String = "UPDATE Question SET Question='" & strquestion & "' WHERE QuestionNum='" & strqnum & "'"
            Dim mycmd As SqlCommand = New SqlCommand(sql, sqlConn)
            sqlConn.Open()
            mycmd.ExecuteNonQuery()
        Catch ex As Exception
            lblnotify1.Text = "The following database error occured:" + _
                      ex.Message()
            sqlConn.Close()
        End Try
    End Sub


please..somebody help!!!
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 6:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC