473,382 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

DataAdapter

JJ
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
Nov 17 '05 #1
5 4525
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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:C9**********************************@microsof t.com...
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

Nov 17 '05 #2
JJ
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" wrote:
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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:C9**********************************@microsof t.com...
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


Nov 17 '05 #3
> 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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:16**********************************@microsof t.com... 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" wrote:
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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:C9**********************************@microsof t.com...
> 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


Nov 17 '05 #4
JJ
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" wrote:
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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:16**********************************@microsof t.com...
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" wrote:
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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:C9**********************************@microsof t.com...
> 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


Nov 17 '05 #5
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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:1C**********************************@microsof t.com...
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" wrote:
> 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
dave@www..jwaonline..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions.microsoft.com> wrote in message news:16**********************************@microsof t.com...
> 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" wrote:
>
>> 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
>> dave@www..jwaonline..com
>> -----------------------------------------------------------------------
>> "JJ" <JJ@discussions.microsoft.com> wrote in message news:C9**********************************@microsof t.com...
>> > 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
>>
>>
>>


Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hch | last post by:
dataAdapter.Update(data, "TableName") won’t work! I was about to deploy my first website on the Internet only to discover that the dataAdapter.Update() throws the Server Error in the third...
3
by: Stephen Noronha | last post by:
I have a question, please correct me if I am wrong. I am assuming that a dataadapter establishes a connection and after filling the dataset or datatable or whatever, will close the connection to...
6
by: Geoff Pennington | last post by:
I have a class method that returns a DataAdapter. I want to access the table(s) contained in the DataAdapter. Of course, accessing the DataSets would be good enough, because I could get the tables...
13
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
7
by: Max | last post by:
I've included the needed tables in the DataSource. Those tables that are bound to controls I can workwith. But how do you get access to the DataAdaptors that are not bound? me.Dataset1.table...
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
3
by: Rich | last post by:
What is the diffeence bewtween a dataAdapter.InsertCommand and dataAdapter.SelectCommand (and dataAdapter.UpdateCommand for that matter)? Dim da As SqlDataAdapter conn.Open da.SelectCommand =...
2
by: BobLewiston | last post by:
I can read in an SQL table ("Person.Contact") from AdventureWorks and step through it one row at a time, but when I try to save a record, either one I'm inserting or one I'm editting, I get the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.