473,385 Members | 1,908 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,385 software developers and data experts.

Retriveing a value from a dataset - VB.NET

Hello

I am new to VB.NET, so sorry if this is really obvious.

I have written the following code to fill my dataset from a stored procedure requiring 1 paramter input (from a SQL database). The Stored Procedure is quite lengthy including a number of inner joins.

The Dataset is used to populate a combobox on a form. I get the combobox to be populated by the dataset correctly based on my query selection. When the combobox selected item is changed, I want to return a value from the Dataset based on a row number (corresponding to the SelectedIndex from my ComboBox) given a Column Name within the dataset.

However, when I get to the SelectedIndexChange procedure the dataset is nothing, even though I have declared the variable as private within the form class (i.e. not within the set up procedure which creates the Dataset).

Code within initial procedure on loading the form:
Expand|Select|Wrap|Line Numbers
  1.             Dim OLEConnect As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(genCONNECTION)
  2.             Dim cmd As OleDbCommand = New OleDbCommand("sp_get_permissioned_single_curves", OLEConnect)
  3.             cmd.CommandType = CommandType.StoredProcedure
  4.             Dim InputValue As OleDbParameter = cmd.Parameters.Add("@curvename", OleDbType.VarChar, 50)
  5.             InputValue.Direction = ParameterDirection.Input
  6.             InputValue.Value = PersistedObjects.LoginUserName
  7.  
  8.             Dim daCurveSetup As OleDbDataAdapter = New OleDbDataAdapter()
  9.             daCurveSetup.SelectCommand = cmd
  10.  
  11.             Dim dsCurveSetup = New DataSet("CurveSetup")
  12.  
  13.             daCurveSetup.Fill(dsCurveSetup, "CurveSetup")
  14.  
  15.             'Add Data to the Curve Combo Box:
  16.             With cmbSingleCurvename
  17.                 .DataSource = dsCurveSetup.Tables("CurveSetup")
  18.                 .DisplayMember = "Curve_Name"
  19.                 .ValueMember = "BaseCurve_Setup_ID"
  20.             End With
  21.  
  22. 'SelectedIndexChange procedure code:
  23.  
  24.     Private Sub cmbSingleCurvename_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSingleCurvename.SelectedIndexChanged
  25.  
  26.             ContractNumber = Me.dsCurveSetup.Tables("CurveSetup").Rows(cmbSingleCurvename.SelectedIndex).Item("Contract_ID")
  27.  
  28.             With cmbContract_Name
  29.                 .SelectedValue = ContractNumber
  30.             End With
  31.  
  32. End Sub
  33.  
Mar 26 '08 #1
4 1952
Plater
7,872 Expert 4TB
The selectedindex changed event gets fired when you apply a datasource to those items, so you should make sure the selectedindex != -1 for starters.

As for why the dataset is nothing, it looks like you declare your dataset inside a function so it's no longer in scope for the index changed event?
Mar 26 '08 #2
Hello - thanks for the reply.

The sub which creates the dataset is called from here:

Private Sub fmCurveSetup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TestAdapter()
End Sub

The Test adapter procedure has the following form, so not a function:

Private Sub TestAdapter()
'Code here....
End Sub

I did a watch on the dataset and as soon as it fills the datasource you are right the selectedindexchanged procedure is called for the combobox, but the dataset is nothing within that procedure, whereas when it returns back to the TestAdapter Sub it is not nothing again.

Bizarrely within the Testadapter I have the following code, where the dataset "dsContracts" does persist on selectedIndexChange events for another comboBox which is activated during the same sub (when the datsource is set):

Dim daContracts As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM tbl_Contracts", genCONNECTION)
dsContracts = New DataSet("Contracts")
daContracts.Fill(dsContracts, "Contracts")

Sorry for long reply but I am really stumped, getting the stored procedure to notice that the input parameter had a value to quite a while...
Mar 26 '08 #3
Plater
7,872 Expert 4TB
Well I see this:
Dim dsCurveSetup = New DataSet("CurveSetup")

Which makes me think that, even if you DID declare dsCurveSetup in the spot where it should be, you are creating and populating a new dataset and not the one defined to be used in all functions
Mar 26 '08 #4
Hello - sorry have been an idiot - I have dim'd the dataset twice (once in the sub and once in the class)!!! Thanks for tips anyway!!
Mar 26 '08 #5

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

Similar topics

5
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets...
1
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
5
by: Christian Ahrenkiel | last post by:
Hi, I've got a DataSet (ds) which was created by a DataAdapter (da) method: ds.Fill(ds). This DataSet is passed through various methods (by value). Each method changes some fields in the...
2
by: Arne | last post by:
Will the dataset below be returned by value or reference? Public Shared Function getDS() As DataSet Dim ds As New DataSet '... do something Return ds End Function
1
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I made web site using asp.net 2.0 Vb.Net. The project depends on database in the local machine. The web site has • Create User Wizard and • Login form When the user is...
0
by: srinivaspnv21 | last post by:
retriveing image in datalist or gridview controls from sql server 2000 in asp.net as well as inserting a image. plz help, thanks in advance
0
by: Sameera | last post by:
Hi, Could any one help me out on how to retriveing the supported formats for the installed Word version in C#. Thanks
0
by: rickbear | last post by:
Hi group... I am having big difficulties with dataset and xsd schemas. First I dedicate a specific schema to a dataset. Then I use an adapter to fill each table in the dataset. But the problem...
4
by: Brad | last post by:
I am trying to convert an XML Stream received from a web api call into a DataSet to use in the rest of the app. The issue I am running into is that it will not convert the stream to a dataset and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.