Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 4th, 2008, 04:02 PM
Registered User
Join Date: Oct 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get a Single Data Value from a Table

How can I simply capture a value from one of my tables and assign it to a variable for use in a form?

I'm developing a windows app with a local database connection. The database is an MS Access 2003 mdb file, and is functioning basically the same as SQL Server--with a datasource, databindingsource, and tableadapter.

One of my forms has no bound controls (however, I can add the databindingsource if necessary). I need to capture a value from one of my tables and assign it to a variable for use in the form.

Here's what I want to get:
select ParentID from Position where PositionID = '1'

MS Access has a VB function that does it in one line:
var = DLookup ( expression, domain, [criteria] )
var = DLookup ( "ParentID", "Position", "PositionID = '1'" )

Doesn't VB2005 have something similar? Or how can I issue a simple sql command?



Reply With Quote
  #2 (permalink)  
Old January 8th, 2008, 02:55 PM
Registered User
Join Date: Oct 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

I found the answer:

Public Class Form1
Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Data.mdb"

Private Sub Form1_Load(...)
Sql1 = "select MainPosID from Options where OptionID = 1"
var = LookupString(Sql1)

Function LookupString(ByVal Sql1 As String)
Dim Ans As String
Using Con As New OleDbConnection(ConStr)
Dim Cmd As New OleDbCommand(Sql1, Con)
Ans = Cmd.ExecuteScalar()
Catch ex As Exception
End Try
End Using
Return Ans
End Function

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple views of single table jatatman ASP.NET 3.5 Basics 1 June 2nd, 2008 01:34 AM
html table data single line -- Solved rupen HTML Code Clinic 1 August 8th, 2005 02:26 PM
Concatenate multiple records from table to single Ron Howerton SQL Language 6 August 23rd, 2004 08:49 AM
Storing complete table rows in a single field KenNeedham Oracle 2 January 22nd, 2004 01:45 PM
RDS Single Record and Table Binding with Access qwerty Classic ASP Databases 0 July 15th, 2003 02:20 PM

All times are GMT -4. The time now is 02:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.