views:

66

answers:

2

This is a small portion of my code file. Each time my debugger reaches the line 'NewDA.Fill(NewDS);' at runtime it jumps to the catch. I'm positive the daynumber variable gets a value that's present in the database and I've tried the query outside of the codefile on my database and it works fine. I'm also using the connectionstring 'db' on more parts of the code with successful results.

string QueryNew = "SELECT activityname AS [Name], activitycategorynumber AS [Category] " + 
                  "FROM ACTIVITY WHERE daynumber = @daynumber";

SqlCommand NewCmd = new SqlCommand(QueryNew, db);
NewCmd.Parameters.Add("@daynumber", SqlDbType.Int).Value = daynumber;
SqlDataAdapter NewDA = new SqlDataAdapter(NewCmd);
DataSet NewDS = new DataSet();
NewDA.Fill(NewDS);
A: 

Have you also verified that daynumber an int in the database? The exception thrown should give you more details about the error.

Andrew
I was able to find the answer in the thrown exception.I forgot to close a datareader I used earlier in the codefile.Thanks for your help!
Brian
A: 

Where you tried NewDA.Fill(NewDS); Instead of it, try NewDA.Fill(NewDS,"<table_name>");

If your table name is ACTIVITY, then try NewDA.Fill(NewDS,"ACTIVITY");

Bibhas