0

我不确定是否有办法做到这一点。我正在尝试使网站的用户能够编辑他们输入的评论。我的讲师不允许我们使用网格视图任务窗格中可用的启用编辑选项,我正在努力寻找解决方案。我知道如何将数据库的内容内容写入下拉列表。但是在为文本框执行此操作时出现错误。我要做的是让用户选择他们为其撰写评论的电影的名称,生成他们为该评论撰写的内容并将其插入文本框中,以便对其进行编辑。这是一件简单的事情吗?还是我需要考虑其他事情?

我用于下拉列表的代码是:

ddlRemoveUreview.DataSource = aDataReader
ddlRemoveUreview.DataTextField = "MovieTitle"
ddlRemoveUreview.DataValueField = "MovieTitle"
ddlRemoveUreview.DataBind()

我为将内容写入文本框而编写的代码:

query = "Select ReviewText FROM MReviewTexts, Movies, UserDetails WHERE MReviewTexts.MReviewID = Movies.MReviewID AND Movies.UserID = UserDetails.UserID AND UserDetails.Username = '" & HttpContext.Current.User.Identity.Name & "'"
Dim cmd = New OleDbCommand(query, dbConnect)
    aDataReader = cmd.ExecuteReader
    If aDataReader.Read() = True Then
        'A row was returned
        txtContent.Text = aDataReader(0)
    Else
        txtContent.Text = "No content entered - please edit"
    End If

得到它的工作。我的 sql 错误 - 正确的解决方案是:

Dim query As String = "Select ReviewText FROM MReviewTexts, MovieReviews, UserDetails WHERE MReviewTexts.MReviewID = MovieReviews.MReviewID AND MovieReviews.UserID = UserDetails.UserID AND UserDetails.Username = '" & HttpContext.Current.User.Identity.Name & "'"
    dbConnect.Open()
    Dim cmd = New OleDbCommand(query, dbConnect)
    aDataReader = cmd.ExecuteReader()
    If aDataReader.Read() = True Then
        'A row was returned
        txtContent.Text = Convert.ToString(aDataReader(0))
    Else
        txtContent.Text = "No content entered - please edit"
    End If
4

1 回答 1

0

此代码有效。它将数据库中的内容显示到文本框中:

Dim query As String = "Select ReviewText FROM MReviewTexts, MovieReviews, UserDetails WHERE MReviewTexts.MReviewID = MovieReviews.MReviewID AND MovieReviews.UserID = UserDetails.UserID AND UserDetails.Username = '" & HttpContext.Current.User.Identity.Name & "'"
dbConnect.Open()
Dim cmd = New OleDbCommand(query, dbConnect)
aDataReader = cmd.ExecuteReader()
If aDataReader.Read() = True Then
    'A row was returned
    txtContent.Text = Convert.ToString(aDataReader(0))
Else
    txtContent.Text = "No content entered - please edit"
End If
于 2012-12-19T20:16:41.950 回答