仅显示我在vb.net中的datareader中的最后一条记录

时间:2013-10-31 13:41:34

标签: sql-server vb.net-2010

在MsgBox中显示数据库结果的最后一行.. 我想使用rows.add函数将sql结果添加到datagrid ..

    Try
        GetDataConn(".", "restaurant", True)
        Dim sqlcmd As New SqlCommand("SELECT i.item_id as 'item', i.item_name as 'name', i.price as 'price', t.item_qty as 'qty' FROM item_tbl i, temp_tbl t WHERE t.item_id = i.item_id AND t.table_id ='" & id.Trim & "' ", sqlConn)
        Dim myreader As SqlDataReader
        myreader = sqlcmd.ExecuteReader()
        myreader.Read()
        While myreader.hasRow()
            'frmMain.posdatagrid.Rows.Add(myreader.Item("item"), myreader.Item("name"), myreader.Item("price"), myreader.Item("qty"), myreader.Item("price") * myreader.Item("qty"))
            MsgBox(myreader.Item("item"))
            myreader.NextResult()
        End While

    Catch ex As Exception
        sqlcmd.Dispose()

    End Try

0 个答案:

没有答案