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

Home Posts Topics Members FAQ

Return a DataSet for Web Application

Most of my background is with VB.Net and WinForm development and I am in the
process of migrating my skills to C# Web Based development. I've come across
something I'm not quite sure how I should handle.

I have a web-page with a asp:GridView on it. In hte Page_Load event of the
page, I create a Dataset and Bind it to the grid as follows:

myGridView.Data Source = dsMyDataSource;
myGridView.Data Bind();

Now, this works OK in testing, but I need to move the DataSource to come
from a module.

I've created a module that builds a DataSet call GetDataSet(); I've created
as follows:

public static DataSet GetDataSet()
{
string strConn = ConfigurationMa nager.Connectio nStrings
"DBName"].ConnectionStri ng;
SqlConnection myConn = new SqlConnection(s trConn);
string strSelectSQL = "SELECT * FROM tUser";
SqlCommand cmdUser = new SqlCommand(strS electSQL, myConn);

SqlDataAdapter adpUser = new SqlDataAdapter( );
adpUser.SelectC ommand = cmdUser;

DataSet dsUser = new DataSet();
adpUser.Fill(ds User);
return dsUser;
}

Now, I get an error "An object reference is required for the non-static
field, method, or property "UserComponents .UserDB.m_strCo nn"" m_strConn is
already a valid connection string as I am using it in other procedures in the
same module. What does this error mean?

I'm trying this approach because populating a GridView control using the
ObjectDataSourc e control does not allow me to provide sorting, so I'm looking
to populate the DataSource for the grid using a Dataset. I'm just not sure
how I can pass a DataSet to the gridControl.Dat aSource using the procedure I
have above.

Thanks.
Oct 16 '08 #1
1 2802
"Greg" <Ac**********@n ewsgroups.nospa mwrote in message
news:D9******** *************** ***********@mic rosoft.com...
[...]
public static DataSet GetDataSet()
{
string strConn = ConfigurationMa nager.Connectio nStrings
"DBName"].ConnectionStri ng;
SqlConnection myConn = new SqlConnection(s trConn);
string strSelectSQL = "SELECT * FROM tUser";
SqlCommand cmdUser = new SqlCommand(strS electSQL, myConn);

SqlDataAdapter adpUser = new SqlDataAdapter( );
adpUser.SelectC ommand = cmdUser;

DataSet dsUser = new DataSet();
adpUser.Fill(ds User);
return dsUser;
}

Now, I get an error "An object reference is required for the non-static
field, method, or property "UserComponents .UserDB.m_strCo nn"" m_strConn is
already a valid connection string as I am using it in other procedures in
the
same module. What does this error mean?
The message means that you are calling the non-static variable m_strConn
from a static method, but it doesn't match the fragment of code that you
provided since there is no m_strConn there. The error has to be somewhere
else in your code.

Since you come from VB and you mention that you have written "a module",
it is worth mentioning that we don't have modules in C#; the closest
equivalent would be a static class. But if you mix both static and
non-static (instance) members in the same class, you need to be aware that
it doesn't make sense to call an instance member from a static one (which
specific instance would the static member be calling?). Don't think about a
module, think about a public class in VB, and do in C# the same things that
you would do in the VB class (replacing "Shared" with "static").

>
I'm trying this approach because populating a GridView control using the
ObjectDataSourc e control does not allow me to provide sorting, so I'm
looking
to populate the DataSource for the grid using a Dataset. I'm just not sure
how I can pass a DataSet to the gridControl.Dat aSource using the procedure
I
have above.

Thanks.
Oct 17 '08 #2

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

Similar topics

2
13058
by: JS | last post by:
I'm trying to create a data layer and having problems returning a DataSet from my code that's in a class module. Please forgive me. I'm new to C# (VB'er). I decided to create my data layer in small steps. Right now, I'm just trying to attach a ComboBox to a dataset that's in my class module. In the class, I call a Stored Procedure. I know how to set up the connection, command, adapter, and dataset, what I'm having a problem with is,...
2
13467
by: Peter Afonin | last post by:
Hello: I'm creating an ASP.Net application. I need to run a method that would return a DataSet. I'm new to C#, so I have a problem with it. In VB.Net I just used to write a function like this: Public Function GetOrders(ByVal sSQL As String) As DataSet In C# when I try to write something like this:
3
13078
by: James Morton | last post by:
I am writing a c# windows forms application. I read in an XML file to a dataset for read-only access (by the user and the application logic). This is not an MDI app but has LOTS of seperate forms. They all need to get to tables within this DataSet. How can I make the DataSet "Global" for all forms within the application. I could just read in the file in every form to a newly instanced dataset (the XML is not that large) but this has...
1
20963
by: R.A. | last post by:
Hi, I have an web service method that accept an xml document and returns a different xml document. Based on the input xml I fill a dataset with information from a database. If the dataset has rows then I need to return those rows to the consumer. I can't tell if the consumer of the web service will use .Net or maybe java. 1) If the web service method returns a Dataset then the consumer will get information on the Dataset. What if the...
3
3712
by: Alpha | last post by:
Hi, I have a window C# application. I update the dataset when user finished entering in a text box. But when I want to update the database when OK is pressed, the if(dsVehicle.HasChanges(DataRowState.Modified)) would return false and update of the dataset would take place. I do notice that if I select other item that the textbox is bind to then the modified indicator would then return true. Is there any code that I can add in the...
0
1133
by: Pat | last post by:
All, I wrote a front end of a sql submitter for lack of better words. Simply I am passing in a query ( strSQL ) built in a text box on the client screen. If it runs, I bind the data to a datagrid, all is well. If there is an error (a mis-spelled field name in a table) the 'catch' catches it along with the e.Message. I just want to pass along the e.Message in the DataSet by manually inserting the text of the e.Message and have the error...
0
1711
by: Ricky A. | last post by:
I'm new to web services, to honest I have never used them before. I need to create a web service that will be located on a web server and called from a winform application. The web service will contain a web method that should return a dataset by executing a stored procedure on the web server. Can anyone point me in the right direction as to how to implement such a web server to return a dataset by executing a stored procedure on a server...
1
2423
by: Steve | last post by:
I have a windows CE application, talking to a C# WebService. In the WebService project I have created a dataset (dsJobList), and there is a web method in there which returns a fully loaded dsJobList dataset to the client, which in this case is a windows CE device. In the code for my application on the WinCE device, I have added a Web Reference to this WebService. Once I have added it I can see the .disco, the ..wsdl and a dsJobList.xsd...
1
6125
by: Anonieko | last post by:
Here are some of the approaches. 1. Transform DataGrid http://www.dotnetjohn.com/articles.aspx?articleid=36 3. Use the Export approach http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp
0
10419
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.