473,395 Members | 2,253 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,395 software developers and data experts.

Help on DataSets

Hello,

I am creating an application using asp.net 2.0. But I am stuck
somewhere. I want to get values from a DataSet one by one on every
Page_Load. So I wrote my code in Page_Load but it didnt work, giving a
warning. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As
  2. System.EventArgs) Handles Me.Load
  3. Dim ds As DataSet1
  4. Dim test As String
  5. test = ds.Tables("pictureID").Rows(0)("pictureID").ToString
  6. Label1.Text = test
  7. End Sub
  8.  
And the Warning:

Variable 'ds' is used before it has been assigned a value. A null
reference exception could result at runtime.
How can I handle this warning. Did I wrote the code in wrong place?

I created my DataSet using the menu in Visual Web Developer (Visual
Studio 2005). So I did not write any code for it.

Am I assigning the ds right?
I also assigned it as DataSet1TableAdapter. But it didnt work also. I
am a rookie so any help is appreciated.

Jul 22 '06 #1
2 2018
DotNetDaddy,

If you want to get individual results focus you than on the datatable. The
dataset is just a very extended wrapper arround that (and around the
relations to that).

Your error is because "ds" in your code is only a placeholder address for an
object which is not filled yet (Is Nothing). You have to set it to, to the
actual object as is created. (Or use that direct)

Cor

"Dot Net Daddy" <ca********@gmail.comschreef in bericht
news:11*********************@m73g2000cwd.googlegro ups.com...
Hello,

I am creating an application using asp.net 2.0. But I am stuck
somewhere. I want to get values from a DataSet one by one on every
Page_Load. So I wrote my code in Page_Load but it didnt work, giving a
warning. Here is my code:

Expand|Select|Wrap|Line Numbers
  1.    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
  2. System.EventArgs) Handles Me.Load
  3.        Dim ds As DataSet1
  4.        Dim test As String
  5.        test = ds.Tables("pictureID").Rows(0)("pictureID").ToString
  6.        Label1.Text = test
  7.    End Sub
  8.  

And the Warning:

Variable 'ds' is used before it has been assigned a value. A null
reference exception could result at runtime.
How can I handle this warning. Did I wrote the code in wrong place?

I created my DataSet using the menu in Visual Web Developer (Visual
Studio 2005). So I did not write any code for it.

Am I assigning the ds right?
I also assigned it as DataSet1TableAdapter. But it didnt work also. I
am a rookie so any help is appreciated.

Jul 23 '06 #2
You need to make ds = New DataSet1, then populate the dataset with data.

T

Dot Net Daddy wrote:
>Hello,

I am creating an application using asp.net 2.0. But I am stuck
somewhere. I want to get values from a DataSet one by one on every
Page_Load. So I wrote my code in Page_Load but it didnt work, giving a
warning. Here is my code:

Expand|Select|Wrap|Line Numbers
  1.    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
  2. System.EventArgs) Handles Me.Load
  3.        Dim ds As DataSet1
  4.        Dim test As String
  5.        test = ds.Tables("pictureID").Rows(0)("pictureID").ToString
  6.        Label1.Text = test
  7.    End Sub

And the Warning:

Variable 'ds' is used before it has been assigned a value. A null
reference exception could result at runtime.
How can I handle this warning. Did I wrote the code in wrong place?

I created my DataSet using the menu in Visual Web Developer (Visual
Studio 2005). So I did not write any code for it.

Am I assigning the ds right?
I also assigned it as DataSet1TableAdapter. But it didnt work also. I
am a rookie so any help is appreciated.
Jul 24 '06 #3

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

Similar topics

0
by: harish | last post by:
Friends. I have three Datasets to be populated to one Excel Workbook. but i need to populate each datasets in to one worksheet. So if i export the datasets to one excel file, sheet1 should have...
4
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...
2
by: Sandy | last post by:
Hello - I am used to retrieving data with stored procedures. DataSets have me baffled inasmuch as it exposes Sql statements directly in the code, however, I think I need to be working with...
6
by: lennon1 | last post by:
Hi, I have already started learning .NET and I have a question. If I want to do anything - Display Data, Navigate, Update - with database (SQL Server) in Visual Studio 2005, do I have to use all...
16
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
4
by: Ronald S. Cook | last post by:
I've always used untyped datasets. In a Microsoft course, it walks through creating typed datasets and harps on the benefits. It has you drag all these things around ..wizard, wizard, wizard......
5
by: Warex | last post by:
I am using the example from the microscuzz site on making a key but It keeps giving me an error: With DataSets.Tables("Numbers") .PrimaryKey = New DataColumn() {.Columns("Number")} End With ...
0
by: S.Tedeschi | last post by:
Hi all; as posted some days ago, I'm converting an on-line app; I used to heavily rely on strongly-typed DataSets directly dropped onto pages, and so viewed by code(-behind) as well. In the next...
12
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...
9
by: gardnern | last post by:
We have X number of data sets, of Y length each. For example... Small, Medium, Large and Red, Green, Blue, Yellow We need to generate a list of all possibilities Small Red
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.