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!!!