2012-12-19 170 views
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 
+0

這是一個網站,作爲一個任務。我已經研究了好幾個小時,並說導師不是很樂意提供關於如何做東西的信息 – user1850189

+0

@ user1850189你沒有發佈相關的代碼到你的問題。請張貼其餘的。 – Icarus

+0

@TLS - 請不要標記作業,它已經過時並被刪除。 – Mike

回答

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 
相關問題