472,780 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

Retriveing a value from a dataset - VB.NET


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
  8.             Dim daCurveSetup As OleDbDataAdapter = New OleDbDataAdapter()
  9.             daCurveSetup.SelectCommand = cmd
  11.             Dim dsCurveSetup = New DataSet("CurveSetup")
  13.             daCurveSetup.Fill(dsCurveSetup, "CurveSetup")
  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
  22. 'SelectedIndexChange procedure code:
  24.     Private Sub cmbSingleCurvename_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSingleCurvename.SelectedIndexChanged
  26.             ContractNumber = Me.dsCurveSetup.Tables("CurveSetup").Rows(cmbSingleCurvename.SelectedIndex).Item("Contract_ID")
  28.             With cmbContract_Name
  29.                 .SelectedValue = ContractNumber
  30.             End With
  32. End Sub
Mar 26 '08 #1
4 1919
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
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
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

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...
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...
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...
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
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...
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
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
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...
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...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.