VB dataset issue

Posted by Gabriel on Stack Overflow See other posts from Stack Overflow or by Gabriel
Published on 2010-01-07T05:56:38Z Indexed on 2010/03/26 11:03 UTC
Read the original article Hit count: 276

Filed under:
|

Hi. The idea was to create a message box that stores my user name, message, and post datetime into the database as messages are sent.

Soon came to realise, what if the user changed his name?

So I decided to use the user id (icn) to identify the message poster instead. However, my chunk of codes keep giving me the same error. Says that there are no rows in the dataset ds2.

I've tried my Query on my SQL and it works perfectly so I really really need help to spot the error in my chunk of codes here.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim name As String Dim icn As String Dim message As String Dim time As String Dim tags As String = ""

    Dim strConn As System.Configuration.ConnectionStringSettings
    strConn = ConfigurationManager.ConnectionStrings("ufadb")

    Dim conn As SqlConnection = New SqlConnection(strConn.ToString())
    Dim cmd As New SqlCommand("Select * From Message", conn)

    Dim daMessages As SqlDataAdapter = New SqlDataAdapter(cmd)
    Dim ds As New DataSet

    cmd.Connection.Open()
    daMessages.Fill(ds, "Messages")
    cmd.Connection.Close()

    If ds.Tables("Messages").Rows.Count > 0 Then
        Dim n As Integer = ds.Tables("Messages").Rows.Count
        Dim i As Integer
        For i = 0 To n - 1
            icn = ds.Tables("Messages").Rows(i).Item("icn")
            Dim cmd2 As New SqlCommand("SELECT name FROM Member inner join Message ON Member.icn = Message.icn WHERE message.icn = @icn", conn)
            cmd2.Parameters.AddWithValue("@icn", icn)
            Dim daName As SqlDataAdapter = New SqlDataAdapter(cmd2)
            Dim ds2 As New DataSet
            cmd2.Connection.Open()
            daName.Fill(ds2, "PosterName")
            cmd2.Connection.Close()
            name = ds2.Tables("PosterName").Rows(0).Item("name")
            message = ds.Tables("Messages").Rows(i).Item("message")
            time = ds.Tables("Messages").Rows(i).Item("timePosted")
            tags = time + vbCrLf + name + ": " + vbCrLf + message + vbCrLf + tags
        Next
        txtBoard.Text = tags
    Else
        txtBoard.Text = "nothing to display"
    End If

End Sub

Help will be very much appreciated as I have been on this simple problem for 2 days.

© Stack Overflow or respective owner

Related posts about visual-studio-2005

Related posts about dataset