473,790 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4581
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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:C9******** *************** ***********@mic rosoft.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.Ta bles["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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:C9******** *************** ***********@mic rosoft.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.Ta bles["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(dsTSHrsMai n1) 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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:16******** *************** ***********@mic rosoft.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.Ta bles["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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:C9******** *************** ***********@mic rosoft.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.Ta bles["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(dsTSHrsMai n1) 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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:16******** *************** ***********@mic rosoft.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.Ta bles["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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:C9******** *************** ***********@mic rosoft.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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:1C******** *************** ***********@mic rosoft.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.Ta bles["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(dsTSHrsMai n1) 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..jwaon line..com
-----------------------------------------------------------------------
"JJ" <JJ@discussions .microsoft.com> wrote in message news:16******** *************** ***********@mic rosoft.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.Ta bles["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..jwaon line..com
>> -----------------------------------------------------------------------
>> "JJ" <JJ@discussions .microsoft.com> wrote in message news:C9******** *************** ***********@mic rosoft.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
4272
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 underline. It was working fine before. ConnectionString in Web.config: ----------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <configuration>
3
2018
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 the DB right??? If yes, is there any reason that the connection get disconnected/timeout and how can i find out what happened? Thanks,
6
1579
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 from there. I can't find a way to do this. Am I missing something? Much obliged.
13
2091
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 OleDbCommand with an SQL String and the connection it has a DataAdapter with the command then it fills the DataSet's DataTable with the streamed data.
8
2698
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. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
2
13969
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
1806
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 is a table with no Insert or Update methods. pll.DataSet1.table has the Row, ChangeEvent, and ChangeEventHandler. It seems like it should be fairly straight forward to use the DataAdapter without binding it to a control. How do you do this?
6
14002
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 = conn da.UpdateCommand.CommandText = "Update tbl1 set fld1 = 'test' where ID = 1" da.Update(tblx) '--tblx/tbl1 not getting updated here.
3
12518
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 = New SqlCommand da.SelectCommand.Connectoin = conn da.SelectCommand.CommandType = Command.Text da.SelectCommand.CommandText = "insert Into tbl1 Select * from tbl2" da.SelectCommand.ExecuteNonQuery
2
2898
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 following exception: Incorrect syntax near ','. Must declare scalar variable "@ContactID". Here's the code: private void btnSave_Click (object sender, EventArgs e) { DataRow row = dataTable.Rows ; ...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.