Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. returning a single value thru an OleDbCommand

returning a single value thru an OleDbCommand

Scheduled Pinned Locked Moved Visual Basic
databasehelpcsharpvisual-studiosecurity
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    medicenpringles
    wrote on last edited by
    #1

    Hello again, I need some help with a simple OLEDB query. I need to return one value from an Access database. the code below is a snapshot of what i have so far. Imports System.Data.OleDb Public Class Prices Public Shared ReadOnly Property Price(ByVal Name As String, ByVal Size As String) As Double Get Dim connString As String = "Data Source=""C:\Documents and Settings\user\" & _ "My Documents\Visual Studio Projects\Quiznos Register\Assoc. Files\Quiznos.mdb"";" & _< "Jet OLEDB:Engine Type=5;" & _ "Provider=""Microsoft.Jet.OLEDB.4.0"";" & _ "persist security info=False;" Dim conn As New OleDbConnection(connString) Dim cmdGetPrice As New OleDbCommand("SELECT Products.Price FROM Products Products WHERE" & _ "(Products.Name='Classic Italian') AND (Products.Size='Small')", conn) Try If conn.State <> ConnectionState.Open Then conn.Open() End If Catch ex As OleDbException MsgBox(ae.Message) End Try Select Case Name Case "Classic Italian" Select Case Size Case "Small" Price = cmdGetPrice.ExecuteNonQuery '<----- This is where it gives me the error. 'other cases for other sizes End Select ' other cases End Select Return Price conn.Close() End Get End Property End Class at the line "Price = cmdGetPrice.ExecuteNonQuery", i get an InvalidOperationException. what do i need to do to return this single value thanks ahead of time, stephen

    _ 1 Reply Last reply
    0
    • M medicenpringles

      Hello again, I need some help with a simple OLEDB query. I need to return one value from an Access database. the code below is a snapshot of what i have so far. Imports System.Data.OleDb Public Class Prices Public Shared ReadOnly Property Price(ByVal Name As String, ByVal Size As String) As Double Get Dim connString As String = "Data Source=""C:\Documents and Settings\user\" & _ "My Documents\Visual Studio Projects\Quiznos Register\Assoc. Files\Quiznos.mdb"";" & _< "Jet OLEDB:Engine Type=5;" & _ "Provider=""Microsoft.Jet.OLEDB.4.0"";" & _ "persist security info=False;" Dim conn As New OleDbConnection(connString) Dim cmdGetPrice As New OleDbCommand("SELECT Products.Price FROM Products Products WHERE" & _ "(Products.Name='Classic Italian') AND (Products.Size='Small')", conn) Try If conn.State <> ConnectionState.Open Then conn.Open() End If Catch ex As OleDbException MsgBox(ae.Message) End Try Select Case Name Case "Classic Italian" Select Case Size Case "Small" Price = cmdGetPrice.ExecuteNonQuery '<----- This is where it gives me the error. 'other cases for other sizes End Select ' other cases End Select Return Price conn.Close() End Get End Property End Class at the line "Price = cmdGetPrice.ExecuteNonQuery", i get an InvalidOperationException. what do i need to do to return this single value thanks ahead of time, stephen

      _ Offline
      _ Offline
      _mubashir
      wrote on last edited by
      #2

      Hello! It seems that your query is returning more than one record.... Try out this query.. SELECT Price FROM Products WHERE (Name='Classic Italian') AND (Size='Small') This is coz no need to give alias when working with a single table. Also check the table 'Products' for rows having same 'Name' and'Size'. If it doesnt work......try to use a dataset to give value to varialble 'Price' _mubashir -- modified at 7:06 Friday 26th August, 2005

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups