473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataAdapter Connection Problem

2 New Member
Hi,
I am trying to run the following code -:
DataAccess Layer Function-:

public DataSet getContacts(str ing Country, string Product)
{
DataSet dsContact = new DataSet();
dsAdapter = new SqlDataAdapter( );
string conString= ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];
mySqlConn = new SqlConnection(c onString);
mySqlConn.Open( );
dsAdapter.Selec tCommand.Connec tion = new SqlConnection(c onString);
dsAdapter.Selec tCommand.Comman dText = "sp_getContactD etails";
dsAdapter.Selec tCommand.Comman dType = CommandType.Sto redProcedure;
dsAdapter.Selec tCommand.Parame ters.Add("@Coun try",Country);
dsAdapter.Selec tCommand.Parame ters.Add("@Prod uct",Product);
dsAdapter.Fill( dsContact);
return dsContact;
}

And the fron end code is-:
getContacts(str ing cntry, string prd)
{
dsContacts = obj.getContacts (cntry, prd);
if (dsContacts.Tab les[0].Rows.Count > 0)
{
pnlHomePage.Vis ible=false;
pnlDispContacts .Enabled = true;
lblDispContacts .Text = dsContacts.Tabl es[0].Rows[0].ToString();
lblDispContacts .Visible=true;
}
else
{
//do something
}
}

The if condition is throwing the error -: System.NullRefe renceException: Object reference not set to an instance of an object
The error is because there there are no tables in the dataset dsContacts;
First problem is the database code is throwing execption at the following line-:
"dsAdapter.Sele ctCommand.Conne ction = new SqlConnection(c onString); "
can anyone show me where the problem is;
the conectivity is working fine for all the other functions except for this one.
Thank You;
Apr 5 '06 #1
1 3026
Tifosi
2 New Member
Hi,
I am trying to run the following code -:
DataAccess Layer Function-:

public DataSet getContacts(str ing Country, string Product)
{
DataSet dsContact = new DataSet();
dsAdapter = new SqlDataAdapter( );
string conString= ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];
mySqlConn = new SqlConnection(c onString);
mySqlConn.Open( );
dsAdapter.Selec tCommand.Connec tion = new SqlConnection(c onString);
dsAdapter.Selec tCommand.Comman dText = "sp_getContactD etails";
dsAdapter.Selec tCommand.Comman dType = CommandType.Sto redProcedure;
dsAdapter.Selec tCommand.Parame ters.Add("@Coun try",Country);
dsAdapter.Selec tCommand.Parame ters.Add("@Prod uct",Product);
dsAdapter.Fill( dsContact);
return dsContact;
}

And the fron end code is-:
getContacts(str ing cntry, string prd)
{
dsContacts = obj.getContacts (cntry, prd);
if (dsContacts.Tab les[0].Rows.Count > 0)
{
pnlHomePage.Vis ible=false;
pnlDispContacts .Enabled = true;
lblDispContacts .Text = dsContacts.Tabl es[0].Rows[0].ToString();
lblDispContacts .Visible=true;
}
else
{
//do something
}
}

The if condition is throwing the error -: System.NullRefe renceException: Object reference not set to an instance of an object
The error is because there there are no tables in the dataset dsContacts;
First problem is the database code is throwing execption at the following line-:
"dsAdapter.Sele ctCommand.Conne ction = new SqlConnection(c onString); "
can anyone show me where the problem is;
the conectivity is working fine for all the other functions except for this one.
Thank You;
Hi,
Got a solution for this one. The code above initializes everything except for one object reference that is SelectCommand . To initialize it we have to pass a command object to the reference of SelectCommand. Sadly it isnt possible to do so through DataAdapter. But still it works fine without it by just allocating the reference of SelectCommand to your command object.
Thank You.
Apr 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2296
by: Dotnetified | last post by:
Reposting after about 2 weeks of no response ... thanks if you can help... ---------------------------------------------------------------------------- -------------- To anyone who thinks they know it all: ;) We recently upgraded our MSDN Version of VS.NET 2002 to VS.NET 2003... Things are all working well, except we've run across a...
20
1646
by: TJ Doherty | last post by:
Need help understanding the following please: When I am creating a project and code my connection using Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Temp\NW-test.MDB", everything works correctly when I run the project. However, if I set up the exact same connection using the DataAdapter wizard and...
3
1996
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,
13
2070
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
2679
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...
6
13981
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.
5
1453
by: limsy | last post by:
Hi ppl, Sorry for asking such a NEWBIE question. I tried looking for answers but cant find. Maybe its too easy. :( I'm used to manual code ADO rather than this .NET wizard and stuff... and i am really having hard time adjusting. *cry* I need to fill a dataadapter with data from a stored procedure. I figured how to create the dataadapter...
5
2919
by: Emil | last post by:
I've created a very simple data base in Microsoft Access 2003. It consists of only one table called "Students" and it contains 2 information about each student: id-student and name. When I try to manipulate data in database I get an error, here's a sample: OleDbConnection connection; connection = new...
0
7711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
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...
0
7805
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...
0
6039
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...
1
5367
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...
1
1932
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
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
755
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...

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.