Error with datagrid

  • Thread starter Thread starter Tonya
  • Start date Start date
T

Tonya

hi,

I am trying to setup a datagrid that pulls values from a
database but i keep getting an error message when i run
the application. Can anyone help me??
The application stops at the line:
da2.fill(ds2)

i keep getting the following error message:

An unhandled exception of
type 'System.Data.SqlClient.SqlException' occurred in
system.data.dll


here is my code leading up to this:

da2 = New SqlDataAdapter("SELECT Meal_Desc, 0 as Quantity
FROM Equipment_Details", Cn)

ds2 = New DataSet("MealBooking")
da2.Fill(ds2)

DGridMealBooking.DataSource = ds2.Tables(0)


this code is in the form_load event.
I have another datagrid being filled just above this one
shown above.

I have instantiated outside of the form load as:
Private da2 as SqlDataAdapter
Private ds2 as dataset

Can anyone help? i have no idea what i have done wrong!!

thx
 
The SQLException doesn't have anything to do with the grid. First make sure
you have a good connection/connectionstring. Then make sure you can run the
query in QA b/c if you have a bad query, it's going to blow up on you..

My guess is that's it's your query, but I'd check the connection too. You
can try just for testing, YourConnection.Open right before the Da.Fill and
make sure it doesn't throw an exception. If it works, it's probably that 0
as a column name.

HTH,

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top