Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7013551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:24:10+00:00 2026-05-27T22:24:10+00:00

I followed an example on stackoverflow about how to read database records into variables.

  • 0

I followed an example on stackoverflow about how to read database records into variables. This is the first time doing this and I feel that I’m close but I’m baffled at this point about the problem.

Here is the link I am referring to:
Visual Basic 2010 DataSet

My code is shown below.

 Public Class Form1
        ' DataSet/DataTable variables
        Dim testdataDataSet As New DataSet
        Dim dttestdataDataTable As New DataTable
        Dim datestdataDataAdapter As New Odbc.OdbcDataAdapter

       ' Variables for retrieved data
       ' Dim sSpeed As String = ""
       ' Dim sFuelprice As String = ""
       Dim sSpeed As Integer
       Dim sFuelprice As Integer


       'Connect to the database 
       ''

       'Fill DataSet and assign to DataTable
       datestdataDataAdapter.Fill(TestdataDataSet , "TestdataDataSet")
       dttestdataDataTable = TestdataDataSet.Tables(0)

      'Extract data from DataTable
      ' Rows is the row of the datatable, item is the column

      sSpeed  = dtTestdataDataTable.Rows(0).Item(0).ToString
      sFuelprice  = dtTestdataDataTable.Rows(0).Item(1).ToString

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    result.Text = Val(miles.Text) * sSpeed * sFuelprice
End Sub

End Class

Basically, I am getting declaration errors and I don’t understand why since the example I was following clearly declared them. I’m connecting to an Access DB called “testdata.mdb” which contains only 1 record with two fields that I want to use throughout the program. The exanple said to dim the variables for each field as strings but this created more dim errors so I made them into integers and remarked out the original dim statements in the meantime (since they’re going to be used in calculations.) The dataadapter and datatable variables also are getting flagged for not being declared when they were earlier in the program. I know this must be a simple thing to fix but I’m just not seeing it.

The form is just a simple thing where the user types in a number and a result is produced by using the numbers read in from the database. In short, I want to be able to do simple calculations with a database within a program and the dim statement thing is getting in the way.

If someone can please clarify what I should do, that would be very much appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:24:11+00:00Added an answer on May 27, 2026 at 10:24 pm

    I apologize for the delay in writing the answer to close off this question and sum it up.

    In my case, it dataset is a one row database called testdata and contains 20 fields.

    The solution that worked is as follows:

    Immediately after the form1_load event, the variables can be immediately written after the dataadapter line:

      Me.TestdataTableAdapter.Fill(Me.fooDataSet.testdata)
    
      speed = Me.fooDataSet.testdata(0).speed
      fuelprice = Me.fooDataSet.testdata(0).fuelprice
      mpg = Me.fooDataSet.testdata(0).mpg
    

    Then just DIM the variables to whatever you want them to be (in this case, speed is an integer, fuelprice is a decimal and MPG is a decimal) right after the PUBLIC CLASS statement at the top of your form’s code.

    You can then manipulate the variables in calculations after a button click as such:

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            fuelcost = CDec((miles.Text/ mpg) * fuelprice)
            txtfuelcost.Text = fuelcost.ToString
     End Sub
    

    Thank you all for your responses!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first of all sorry if this isn't formatted correctly, first time doing this. I've
First time posting in Stack Overflow, hope I'm doing this right. I'm writing an
I found and followed an example from Stackoverflow (http://stackoverflow.com/questions/2310139/how-to-read-xml-response-from-a-url-in-java) of how to read an
I've followed this example: RCP+JavaWS but the app just briefly comes up and goes
Followed this question about delayed_job and monit Its working on my development machine. But
I followed this tutorial on configuring the Rails plugin ExceptionNotifier. I know that I
I've just followed this example from Wordpress and I have successfully added an extra
Hi i have a problem with recursion. i followed this example from wc3 http://www.w3schools.com/jsref/met_win_settimeout.asp
Followed this example on telerik's website and implemented as follows:- aspx page:- <div id=div1
I followed the example: http://arunranga.com/examples/access-control/credentialedRequest.html from this page: http://arunranga.com/examples/access-control/ The example work in Firefox,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.