我不确定是否有办法做到这一点。我正在尝试让网站用户编辑他们输入的评论。我的讲师不会让我们使用网格视图任务窗格中提供的启用编辑选项,我很难找到解决方案。我知道如何将数据库的内容内容写入下拉列表。但是我在为文本框做这个时遇到错误。我要做的是让用户选择他们为评论编写的电影的名称,生成他们为评论编写的内容并将其插入文本框以便进行编辑。这是一件简单的事吗?或者我需要考虑其他事情吗?
我用于下拉列表的代码是:
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
答案 0 :(得分: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