Generated Code Won't Compile

  • Thread starter Thread starter Curt Emich
  • Start date Start date
C

Curt Emich

I'm trying to create a dataset. I start by creating a connection. Then I
create and configure a data adapter. Finally, I select "generate dataset"
after right-clicking on the data adapter. It creates a dataset and puts it
under the form, just like the connection and the adapter.

When I try to compile the code GENERTED BY THE IDE, it bombs. Here's the
code:

protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;

protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;

protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

protected TrainOfThought.DataSet1 dataSet11;



It bombs on the last line. It says that the type or namespace "DataSet1"
does not exist. I never said it did. Does anyone know why .NET would bomb
on its own code? What can I do to fix this?
 
Curt said:
I'm trying to create a dataset. I start by creating a connection. Then I
create and configure a data adapter. Finally, I select "generate dataset"
after right-clicking on the data adapter. It creates a dataset and puts it
under the form, just like the connection and the adapter.

When I try to compile the code GENERTED BY THE IDE, it bombs. Here's the
code:

protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;

protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;

protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

protected TrainOfThought.DataSet1 dataSet11;



It bombs on the last line. It says that the type or namespace "DataSet1"
does not exist. I never said it did. Does anyone know why .NET would bomb
on its own code? What can I do to fix this?

Did you add the generated dataset to your project?

Frans.
 
Hi Curt,

I am not sure what it does in C# however sometimes in VB the code stays in
the designer when you make some corrections afterwards .

Did you try it with a new project again?.

Cor
 
Hi Curt:

A few questions:

First, if you look in the solution explorer, do you see a xsd that matches
the one you just made? I'm just wondering b/c I've repeated the steps you
mentioned and it worked by default. However, this is the actual reference
line it generated:
<<protected TrainOfThought.DataSet1 dataSet11;>>
Basically the same as yours other than the form name and the access
modifier. That's not surprising. However, my project has the DataSet1.xsd.
However, if I right click on DataSet1.xsd in the solution explorer and
choose Exclude from Project.. I still have my declaration as above but I
know get this exception when I try to compile:
<<C:\WindowsApplication5\Form1.cs(33): The type or namespace name 'DataSet1'
does not exist in the class or namespace 'WindowsApplication5' (are you
missing an assembly reference?)>> Which is the same thing you are having.

Just to see if this may have happened accidentally , select the Project menu
item and then check Show All Files. See if it doesn't appear afterward (it
so, it will probably have a blank white icon instead of your typical form
icons or class icons.

2) I'm not sure what options you chose when you generated the dataset. You
have a choice where to gen the new dataset, in a new one or an existing one.
You'll should have a choice of each table that you've created a dataadapter
for that has a Select Command. Finally, there's an option for adding the
dataset to the designer. I'm just wondering which options you chose (New
vs. Existing, and did you unchoose the Add DataSet to designer option?

I think the most likely culprit is that the xsd somehow was excluded or
there was an error when generating it. As such, it's not visible to your
class so it's raising the error. If you choose Show all files and you see
it, then just include it in the project and it should be fine. If not, then
it must have either never been generated correctly or somehow got deleted.
IF that's the case, delete the line causing the exception and just start ove
r again with generating the dataset. It should be fine.

Finally, what do you mean by the comment "It says that the type or namespace
"DataSet1"
does not exist. I never said it did. " when you say "I never said it
did"? That makes me think it was excluded or specifically you didn't chose
the add to designer option, but that's purely conjecture and that's why I
mention it. Since I think the most likely problem is the exlusion of the
file, that's probably what caused it if my guess is correct (but like I
said, it's just a guess that's why I ask).
Let me know and hopefully we can get to the bottom of it.

Cheers

Bill
 
Those .xsd files were there, but they still didn't work. I manually
typed in a dataset, and it works fine. I just thought the IDE would be
more reliable. Thanks to everyone for your feedback.
 
It's pretty reliable but it's not infallible. There's a lot that can go
wrong. and considering the possibilities, it's impressive it works as well
as it does. I'm glad you got it fixed though.

Cheers,

Bill
 
Back
Top