|
VB.NET • Insert a New Review Listing 3. You add a new review either by appending it to the existing XML product file or by creating a new one. The InsertReview method accepts the author name, the review content, and the vote as parameters. Public Sub InsertReview(ByVal Author As String, _
ByVal Review As String, ByVal Vote As Integer)
Try
Dim strXMLPath As String
If ProductID > 0 Then
If m_strXMLPath.EndsWith("\") = False Then
strXMLPath = m_strXMLPath & "\" & _
m_lProductID.ToString() & ".xml"
Else
strXMLPath = m_strXMLPath & _
m_lProductID.ToString() & ".xml"
End If
Dim fe As New FileInfo(strXMLPath)
Dim r As dsReviews.REVIEWRow
r = m_dsReviews.REVIEW.NewREVIEWRow()
If fe.Exists() Then
m_dsReviews.ReadXml(strXMLPath)
m_dsReviews.REVIEW.DefaultView.Sort _
= "ID_REVIEW DESC"
Dim iNewID As Integer = _
m_dsReviews.REVIEW.DefaultView(0)(0) _
+ 1
r.ID_REVIEW = iNewID
Else
r.ID_REVIEW = 1
End If
r.AUTHOR = Author
r.REVIEW = Review
r.VOTE = Vote
m_dsReviews.REVIEW.AddREVIEWRow(r)
m_dsReviews.WriteXml(strXMLPath)
End If
Catch ex As Exception
End Try
End Sub
|