1
Reply

VERY basic one..

Boblysan

Boblysan

Apr 2 2005 9:44 PM
2k
Ok, I am trying to perform what I believe to be an extremely simple task and am having difficulty. I am attempting to connect to an SQL database and retrieve a first name and last name based on a customer ID. I know the SQL is good as I can run it in query analyzer and it works fine. I can successfully open a connection to the DB in my application but can not figure out how to get the information from the database via the SQLDataReader (or any other method for that matter) conn.Open(); MessageBox.Show("Connection Opened!!"); SqlCommand cmd = new SqlCommand("SELECT RTRIM (C536870914) + ' ' + RTRIM(C536870913) NAME, C536870980 PHONELOOKUP FROM ARSYSTEM.DBO.T55 WHERE C536870980 = " + txtCustID.Text, conn); reader = cmd.ExecuteReader(); string custName = reader[0].ToString(); txtCustName.Text = custName; When I run this application and attempt execute the above method I receive the following error. An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll Additional information: Invalid attempt to read when no data is present. I'm not sure why it says no data is present as when I run this query elsewhere it does return data. Any thoughts? Thanks, Bob

Answers (1)