Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2006, 03:59 AM
Authorized User
 
Join Date: Nov 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to store "SELECT" command value?

Dear All,

I am using VB .NET 2003, I would like to store the fetched value in "SELECT " command. Please refer the following code.
dim sqlconn as sqlconnection = "............."
dim sql as string = nothing
sql = "SELECT itemname FROM ItemMaster where itemname='Book'"
cmd = new sqlcommand(sql,sqlconn)
sqlconn.open()
...
....
...
In the above code, it fetches the value but how to take that value into another variable. Please give me a complete code list so that I can try from my end here.
Expecting your reply.
venki.

VENKATESH
__________________
VENKATESH
 
Old March 16th, 2006, 06:01 AM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is how I do it using an MS Access database. It's easy to convert to MS SQL

        Dim Cmd As OleDb.OleDbCommand
        Dim Con As OleDb.OleDbConnection
        Dim Reader As OleDb.OleDbDataReader
        Dim Sql As String = Nothing
        Dim Book As String = Nothing

        Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleD b.4.0;data source=" & Database & "")
        Sql = "SELECT [itemname] FROM [ItemMaster] where itemname='Book'"
        Cmd = New OleDb.OleDbCommand(Sql, Con)

        Con.Open()
        Reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
        If Reader.Read() Then
            Book = Reader("itemname").ToString
        End If
        Con.Close()

Please let me know how you get on with it.

Thanks
Pete*






Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL said: select command denied to user: 'root@ surendran MySQL 2 September 9th, 2010 12:27 AM
Changing SqlDatasource select command in codebehin mallikalapati ASP.NET 2.0 Professional 2 March 28th, 2008 08:02 AM
Change the Select Command of a DataAdapter from th Manolis_Perrakis ASP.NET 2.0 Basics 0 October 20th, 2006 10:56 AM
Select Command jaucourt ADO.NET 8 January 28th, 2004 11:34 AM





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