473,785 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datasets - Urgent!!@

I have the follow code:

private void crear() {

//creating a dataset

DataSet myDataset=null;
SqlConnection sqlConnection=n ull;
SqlDataAdapter sqlCommand=null ;
try {
//create an instance for a SqlConnection and a Sql Command

sqlConnection = new SqlConnection(" server=.; database=JF;
Trusted_Connect ion=false; uid=sa; pwd=; Pooling=true;") ;
sqlCommand = new SqlDataAdapter( "select
cantidad,concep to,prec_unit,va lor_venta from fact_detalle",s qlConnection);
myDataset = new DataSet();

//mark the command as a text
sqlCommand.Sele ctCommand.Comma ndType = CommandType.Tex t;

//open the connection and execute
sqlConnection.O pen();
sqlCommand.Fill (myDataset);

}
catch {
throw;
}
finally {
if(sqlConnectio n!=null)
sqlConnection.C lose();
// MessageBox.Show ("The connection is close");
}
// return myDataset;

dataGrid1.DataS ource=myDataset .Tables[0];
}
private void nueva_fila()

{
DataRow anyRow = myDataset.Table s[0].NewRow();
}
---------------------------------
on nueva_fila there´s an error , when compila the "myDataset" is underlined
and the follow task is shown:

The type or namespace name 'myDataset' could not be found (are you missing a
using directive or an assembly reference?)
---
Why?, it´s because the first void is private.... please help me
Dec 17 '05 #1
1 1252
Alex,

First of all you need in my opinion only 50% of the code you use at the
moment.

It is complete nonsense to create an object in a try catch block, because
that cannot throw an exception. The same is for all others, it is only
needed for your method dataadapter.fil l (because that it has an inbuild open
and close, is even the open and close not needed). For your Try catch finaly
you can use a Using block.

At last your error, that is because the dataset is created in the method
"crear", therefore you have no direct reference any more to it although that
it exist because it has at least a reference to the DataGrid.

You can get it in the method nuava_fila in a way as
DataTable myDataTable = (DataTable)Data grid1.DataSourc e

Or you can declare your mydataset global in your class.

I hope that this gives some idea's

Cor

private void crear() {

SqlConnection sqlConnection = new SqlConnection(" server=.; database=JF;
Trusted_Connect ion=false; uid=sa; pwd=; Pooling=true;") ;
sqlCommand = new SqlDataAdapter( "select
cantidad,concep to,prec_unit,va lor_venta from fact_detalle",s qlConnection);
myDataset = new DataSet();

//mark the command as a text
sqlCommand.Sele ctCommand.Comma ndType = CommandType.Tex t;

//open the connection and execute
sqlConnection.O pen();
sqlCommand.Fill (myDataset);

}
catch {
throw;
}
finally {
if(sqlConnectio n!=null)
sqlConnection.C lose();
// MessageBox.Show ("The connection is close");
}
// return myDataset;

dataGrid1.DataS ource=myDataset .Tables[0];
}
private void nueva_fila()

{
DataRow anyRow = myDataset.Table s[0].NewRow();
}
---------------------------------
on nueva_fila there´s an error , when compila the "myDataset" is
underlined
and the follow task is shown:

The type or namespace name 'myDataset' could not be found (are you missing
a
using directive or an assembly reference?)
---
Why?, it´s because the first void is private.... please help me

Dec 18 '05 #2

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

Similar topics

4
1738
by: Alpha | last post by:
I have a small Window application and through out the different forms I create a different dataset. At the begining I used the Tools to drag and drop the SqlDataAdapter, connection and dataset objects to the frist few forms but then later I removed those and created these objects in my code. I now see 3 datasets in the Solution Explorer panel part but not all the datasets that I have in my codes. Are these 3 datasets leftover from the...
1
993
by: Alex | last post by:
I have the follow code: private void crear() { //creating a dataset DataSet myDataset=null; SqlConnection sqlConnection=null; SqlDataAdapter sqlCommand=null; try {
9
2917
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... There are articles on the new TableAdapters where it says that a key new advantage is that a single TableAdapter, which can have multiple queries, can be used on multiple forms. Now that was in an article on using TableAdapters with...
7
2875
by: Ryan | last post by:
Quite awile ago I posted to this newsgroup in regards to using Datasets in my VB 2005 application. About how many Datasets should be used.. a limit to the number of tables that should be included in a dataset, etc. The concensus I was given was that one Dataset should be created per logical set of data, or approximately 1 Dataset per form (usually consisting of 5 or less tables). After finishing 2 projects using VB 2005 and DataSets I...
12
4161
by: Simon | last post by:
Hi all, I'm having a baffling problem with a windows service that I'm working on. Basically, I am using a typed dataset to insert a large number of rows into an SQL Server 2005 database. But there's a memory leak that seems to be to do with calling the data adapters update method. It's making the memory usage go through the roof and ultimately the service crashes after running out of memory.
4
1201
by: mohitkatariya | last post by:
i m making relation between 2 datasets but i m geting an error msg that some rows may not be in parent table how can i solve this prblm. its urgent
2
2377
by: itsvineeth209 | last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc. U had created table login with fields username(varchar(50)), password(varchar(50)), firstname(varchar(50)), lastname(varchar(50)). U had to display username , first name, last name in default.aspx page after login. One more condition is that, if user fails login...
12
3604
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a gridview, for example, I loop through a datareader, populating an array list with instances of a custom class in the middle tier, and then send the array list up to the presentation layer and bind the gridview to it. If I use a typed dataset, I...
6
5365
by: Bobby Edward | last post by:
Using ASP.NET 3.5 and MySQL (thru DevArt MyDirect.NET)... On the production server I get a "Parser Error" for every XSD dataset. It works perfect on my dev machine. But, on the production server I get the error. To troubleshoot the issue I went back to my dev machine and changed all the connectionstrings from localhost to the remote/production server db and made sure everything works fine. I then uploaded all the files to the...
0
9647
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
9491
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,...
0
10357
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
9959
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
8988
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
7510
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
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
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

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.