locked
Pulling my hair out RRS feed

  • Question

  • User-1792101031 posted

    Hi,

     

     I wonder if you can help me, I am pulling my hair out with this code. I have an Access 2007 database that I am trying to display entries in a table format. I can pull the first column of the first record but when the datareader attempts to access the second colum of the record I get a IndexOutOfRangeException , even though there is data in there. I have tried to capture it with a is nothing statement to ensure data integrity but it still crashes at that point. i am not sure what I am doing wrong. I suspect its something to do with my SELECT statement.

    All data in database is in uppercase

    The code snippet for the offending code is below:

     

    'Build SQL commands

    mySQLCommand.Connection = sender

    mySQLCommand.CommandText =
    "SELECT Hostname_Table.*, User_Table.* " & _

    "FROM User_Table RIGHT JOIN (Hostname_Table LEFT JOIN Asset_Table " & _

    "ON Hostname_Table.PC_Name = Asset_Table.PC_Name) " & _

    "ON User_Table.User_Name = Hostname_Table.User_Name " & _

    "WHERE Hostname_Table.PC_Name LIKE '%" & _

    SearchText.Value.ToUpper & "%'"

     

    myReader = mySQLCommand.ExecuteReader

    'Read and display data inside results table

    Dim i As Integer = 0

    Do While myReader.Read = True

    Status.InnerHtml = i

    i += 1

    'Hostname

    tblRow = New TableRowtblCell.Text = myReader("Hostname_Table.User_Name").ToString()

    tblRow.Cells.Add(tblCell)

    'Serial Number

    tblCell = New TableCelltblCell.Text = myReader("Hostname_Table.BCP_Flag").ToString()   (IF FAILS ON THIS LINE,)

    tblRow.Cells.Add(tblCell)

    'Asset Number

    tblCell = New TableCell

    ' tblCell.Text = myReader("aAssetNumber").ToString()

    tblRow.Cells.Add(tblCell)

    'Make

    tblCell = New TableCell

    ' tblCell.Text = myReader("aMake").ToString()

    tblRow.Cells.Add(tblCell)

    'Model

    tblCell = New TableCell

     

     

     

    Monday, January 5, 2009 2:07 AM

Answers

  • User-821857111 posted

    Rather than creating an HTML table like this, why don't you simply bind the DataReader to a GridView?  Failing that (which will save you loads of time) reference the items in the Reader through their ordinal position - I suspect that it's the table names that are causing the problem.  You shouldn't be able to reference any items in the Reader using that dot notation.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 5, 2009 2:24 AM
  • User-821857111 posted

    Yes, it's possible by adding a TemplateField and adding a HyperLink control to it.  Bind the UserName to the HyperLink control.

    http://msdn.microsoft.com/en-us/library/aa479353.aspx

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 6, 2009 2:24 AM

All replies

  • User-821857111 posted

    Rather than creating an HTML table like this, why don't you simply bind the DataReader to a GridView?  Failing that (which will save you loads of time) reference the items in the Reader through their ordinal position - I suspect that it's the table names that are causing the problem.  You shouldn't be able to reference any items in the Reader using that dot notation.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 5, 2009 2:24 AM
  • User-1792101031 posted
    Oh right, let me give that a bash :), thanks
    Monday, January 5, 2009 3:53 AM
  • User-1792101031 posted
    Its funny though, I built this all on a single table SQL database without any issue, then split it up into 3 tables in Access and all hell broke loose. Had no problems doing the datareader(table.record) thing but dataview sounds better. will try tomorrow and let you know, thanks for the reply
    Monday, January 5, 2009 3:58 AM
  • User-1792101031 posted

    That worked however, how can I build a dynamic table with hyperlinks on certain cells using this method?  For instance, the search results produces a row for the asset searched. If that row has a username associated to it, I  wanted to hyperlink that username so if a user clicked on it, it will pull up a child window with the usernames details(full name, cost centre, business approver, upline manager etc etc). I dont see how I can do this in Gridview, would this be possible?

    Monday, January 5, 2009 7:40 PM
  • User-821857111 posted

    Yes, it's possible by adding a TemplateField and adding a HyperLink control to it.  Bind the UserName to the HyperLink control.

    http://msdn.microsoft.com/en-us/library/aa479353.aspx

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 6, 2009 2:24 AM