Invalid attempt to access a file before calling Read()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbewers1
    New Member
    • Feb 2009
    • 68

    #1

    Invalid attempt to access a file before calling Read()

    Hi,

    I'm getting the following error when executing the SQL within this line of code.
    Originally, I had coded a stored procedure within the code but this brought up the same error.

    I've looked for help elsewhere on the net but can't seem to find anything specific to what I need to resolve this. And I need to use MySqlDataReader so that I can use .GetOrdinal to get the positioning of the columns correct.

    Anyone else had and resolved this problem?

    Code:
    public DataTable GetBibtexPaperDetails(string file)
            {
                using (MySqlConnection sqlCon = new MySqlConnection(ConnectionString))
                {
                    sqlCon.Open();
                    MySqlCommand command = sqlCon.CreateCommand();
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = 
                        string.Format(@"SELECT * FROM PROJmb326.Paper p
                          WHERE p.Title LIKE '{0}' OR p.Keywords LIKE '{0}'
    	                  ORDER BY p.Title ASC", file);
                    
                    DataTable ds = new DataTable();
                    using(MySqlDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            ds.Columns.Add();
                            ds.Rows.Add(dr.GetOrdinal("Author1Firstname").ToString());
                            ds.Rows.Add(dr.GetOrdinal("Author1Surname").ToString());
                        }
                    }
                    return ds;
                }
            }
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    where's the error?......... ............... ............... ...............

    Comment

    Working...