DataAdapter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I created a DataAdapter, connection object and dataset generated from
DataAdapter by dragging DataAdapter compenent to win form. Now in the code
behind I want to use that DataAdapter. I go to use the dataset that was
generated from DataAdapter and I get an Object ref error. So do I have to go
through the steps in code behind to reinitate the SqlDataAdapter and DataSet
that I generated on the form? If so whats the purpose of having the wizard
generate a SqlDataAdapter on the form to use? The SqlDataAdapter Wiz created
all my stored procedures in my database. So in code behind I would need to
resetup the SqlDataAdapter to use those sp's. That doesn't make sense. What
do I need to do in order to use the generated SqlDataAdapter and DataSet?

Thanks,
JJ
 
The wizard that places the Adapter in the component tray on your design-time form will also place the initialization code for the
adapter in the code-behind. This means it's immediately usable by calling code (in-scope) without having to reinitialize it.

What do you mean by Object ref error? What is the exact error? Is it occuring at runtime or compile-time?
 
Hi Dave,

Ok I have a SqlDataAdapter on form named daEmpHrs and a DataSet generated
by it called dsTSHrsMain1. Now in Code behind I call the following :

DataRow oHrsRow = dsTSHrsMain1.Tables["Hours"].NewRow();

and I get the Error:
"Object instance not set to instance of object"

The only thing I can think of is that Table "Hours" doesn't exist yet in
Dataset.
If not Do I have to call the Fill command first on SqlDataAdapter and
dataset in order to use it? I would believe that as soon as my form came into
existence the SqlDataAdapter would automatically fill the dataset that
corresponds with it on form.


Thanks,
JJ
 
DataRow oHrsRow = dsTSHrsMain1.Tables["Hours"].NewRow();
and I get the Error:
"Object instance not set to instance of object"

Probably because Tables["Hours"] is returning null.
The only thing I can think of is that Table "Hours" doesn't exist yet in
Dataset.

It exists, but most likely with a different name. Open the DataSet in the designer to see what the name of the table is.
It will most likely be "Table" or "Table1" or "Table2", etc. depending on the number of tables in your DataSet.
If not Do I have to call the Fill command first on SqlDataAdapter and
dataset in order to use it?

No, the DataSet has already been initialized, although it will not contain any data.
I would believe that as soon as my form came into
existence the SqlDataAdapter would automatically fill the dataset that
corresponds with it on form.

No, you have to call SqlDataAdapter.Fill(dsTSHrsMain1) in your code-behind to fill the data. If the SelectCommand of the Adapter
requires input parameter values, you must specify them before calling the Fill() method.

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
JJ said:
Hi Dave,

Ok I have a SqlDataAdapter on form named daEmpHrs and a DataSet generated
by it called dsTSHrsMain1. Now in Code behind I call the following :

DataRow oHrsRow = dsTSHrsMain1.Tables["Hours"].NewRow();

and I get the Error:
"Object instance not set to instance of object"

The only thing I can think of is that Table "Hours" doesn't exist yet in
Dataset.
If not Do I have to call the Fill command first on SqlDataAdapter and
dataset in order to use it? I would believe that as soon as my form came into
existence the SqlDataAdapter would automatically fill the dataset that
corresponds with it on form.


Thanks,
JJ

Dave said:
The wizard that places the Adapter in the component tray on your design-time form will also place the initialization code for the
adapter in the code-behind. This means it's immediately usable by calling code (in-scope) without having to reinitialize it.

What do you mean by Object ref error? What is the exact error? Is it occuring at runtime or compile-time?
 
Hi Dave,

You are correct I had found out yesterday that my Table name was not
correct. I found it ot by digging through the codebehind class of the dataset
dsTSHrsMain1.
After fixing this I was good to go.

Thanks,

JJ


Dave said:
DataRow oHrsRow = dsTSHrsMain1.Tables["Hours"].NewRow();

and I get the Error:
"Object instance not set to instance of object"

Probably because Tables["Hours"] is returning null.
The only thing I can think of is that Table "Hours" doesn't exist yet in
Dataset.

It exists, but most likely with a different name. Open the DataSet in the designer to see what the name of the table is.
It will most likely be "Table" or "Table1" or "Table2", etc. depending on the number of tables in your DataSet.
If not Do I have to call the Fill command first on SqlDataAdapter and
dataset in order to use it?

No, the DataSet has already been initialized, although it will not contain any data.
I would believe that as soon as my form came into
existence the SqlDataAdapter would automatically fill the dataset that
corresponds with it on form.

No, you have to call SqlDataAdapter.Fill(dsTSHrsMain1) in your code-behind to fill the data. If the SelectCommand of the Adapter
requires input parameter values, you must specify them before calling the Fill() method.

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
JJ said:
Hi Dave,

Ok I have a SqlDataAdapter on form named daEmpHrs and a DataSet generated
by it called dsTSHrsMain1. Now in Code behind I call the following :

DataRow oHrsRow = dsTSHrsMain1.Tables["Hours"].NewRow();

and I get the Error:
"Object instance not set to instance of object"

The only thing I can think of is that Table "Hours" doesn't exist yet in
Dataset.
If not Do I have to call the Fill command first on SqlDataAdapter and
dataset in order to use it? I would believe that as soon as my form came into
existence the SqlDataAdapter would automatically fill the dataset that
corresponds with it on form.


Thanks,
JJ

Dave said:
The wizard that places the Adapter in the component tray on your design-time form will also place the initialization code for the
adapter in the code-behind. This means it's immediately usable by calling code (in-scope) without having to reinitialize it.

What do you mean by Object ref error? What is the exact error? Is it occuring at runtime or compile-time?

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
Hi,

I created a DataAdapter, connection object and dataset generated from
DataAdapter by dragging DataAdapter compenent to win form. Now in the code
behind I want to use that DataAdapter. I go to use the dataset that was
generated from DataAdapter and I get an Object ref error. So do I have to go
through the steps in code behind to reinitate the SqlDataAdapter and DataSet
that I generated on the form? If so whats the purpose of having the wizard
generate a SqlDataAdapter on the form to use? The SqlDataAdapter Wiz created
all my stored procedures in my database. So in code behind I would need to
resetup the SqlDataAdapter to use those sp's. That doesn't make sense. What
do I need to do in order to use the generated SqlDataAdapter and DataSet?

Thanks,
JJ
 
For future reference, you don't have to look in the code-behind of strong-typed DataSets to find the table names. This can be done
by loading the DataSet into the VS.NET designer and looking at the top of each table definition. The name of the table is in the
TextBox.

For more control, click "Xml" on the bottom-left corner of the designer to see the XML implementation of the DataSet. The xsd.exe
tool uses the XML to serialize the code-behind for your DataSet. Updates that you make to either the designer or XML will be
reflected in the code-behind.

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
JJ said:
Hi Dave,

You are correct I had found out yesterday that my Table name was not
correct. I found it ot by digging through the codebehind class of the dataset
dsTSHrsMain1.
After fixing this I was good to go.

Thanks,

JJ


Dave said:
DataRow oHrsRow = dsTSHrsMain1.Tables["Hours"].NewRow();

and I get the Error:
"Object instance not set to instance of object"

Probably because Tables["Hours"] is returning null.
The only thing I can think of is that Table "Hours" doesn't exist yet in
Dataset.

It exists, but most likely with a different name. Open the DataSet in the designer to see what the name of the table is.
It will most likely be "Table" or "Table1" or "Table2", etc. depending on the number of tables in your DataSet.
If not Do I have to call the Fill command first on SqlDataAdapter and
dataset in order to use it?

No, the DataSet has already been initialized, although it will not contain any data.
I would believe that as soon as my form came into
existence the SqlDataAdapter would automatically fill the dataset that
corresponds with it on form.

No, you have to call SqlDataAdapter.Fill(dsTSHrsMain1) in your code-behind to fill the data. If the SelectCommand of the Adapter
requires input parameter values, you must specify them before calling the Fill() method.

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
JJ said:
Hi Dave,

Ok I have a SqlDataAdapter on form named daEmpHrs and a DataSet generated
by it called dsTSHrsMain1. Now in Code behind I call the following :

DataRow oHrsRow = dsTSHrsMain1.Tables["Hours"].NewRow();

and I get the Error:
"Object instance not set to instance of object"

The only thing I can think of is that Table "Hours" doesn't exist yet in
Dataset.
If not Do I have to call the Fill command first on SqlDataAdapter and
dataset in order to use it? I would believe that as soon as my form came into
existence the SqlDataAdapter would automatically fill the dataset that
corresponds with it on form.


Thanks,
JJ

:

The wizard that places the Adapter in the component tray on your design-time form will also place the initialization code for
the
adapter in the code-behind. This means it's immediately usable by calling code (in-scope) without having to reinitialize it.

What do you mean by Object ref error? What is the exact error? Is it occuring at runtime or compile-time?

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
Hi,

I created a DataAdapter, connection object and dataset generated from
DataAdapter by dragging DataAdapter compenent to win form. Now in the code
behind I want to use that DataAdapter. I go to use the dataset that was
generated from DataAdapter and I get an Object ref error. So do I have to go
through the steps in code behind to reinitate the SqlDataAdapter and DataSet
that I generated on the form? If so whats the purpose of having the wizard
generate a SqlDataAdapter on the form to use? The SqlDataAdapter Wiz created
all my stored procedures in my database. So in code behind I would need to
resetup the SqlDataAdapter to use those sp's. That doesn't make sense. What
do I need to do in order to use the generated SqlDataAdapter and DataSet?

Thanks,
JJ
 
Back
Top