Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.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 August 26th, 2004, 04:18 AM
Authorized User
 
Join Date: Jul 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default collect a number

I've a query
cmdmax = New SqlCommand("select max(Q_ID) as maxid from Question", conPubs)
Now i want to collect the returened number,in which i can store
this No. ,so that i can use this further.

abhinavjain
__________________
abhinavjain
 
Old August 26th, 2004, 07:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

cmdmax.ExecuteScalar() returns a single integer value. Use that method to return to an integer value.

Brian
 
Old August 27th, 2004, 05:58 AM
Authorized User
 
Join Date: Jul 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I write following code

Dim max as integer
cmdmax = New SqlCommand("select max(Q_ID) from Titles", conPubs)
max = cmdmax.ExecuteScalar
TextBox2.Text = max

But it is not working ,what's the problem

abhinavjain
 
Old August 27th, 2004, 08:17 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

try this...
Code:
'...
max = CType(cmdmax.ExecuteScalar(),Int32)
TextBox2.Text = max.ToString()

--------------------------------------------
Mehdi.:)
 
Old August 30th, 2004, 07:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

If you have Option Strict On, you have to CType the value. Otherwise, the problem is with your query.

What is the specific error that you are getting?

Brian
 
Old September 1st, 2004, 12:16 AM
Authorized User
 
Join Date: Jul 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no error msg,but actully i want that i get maximun ID from table
and then add 1 to that number
ie max1=max+1

abhinavjain
 
Old September 1st, 2004, 09:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Yeah OK, use ExecuteScalar()





Similar Threads
Thread Thread Starter Forum Replies Last Post
Oracle stored proc Bulk Collect kulkarnimonica ADO.NET 1 November 6th, 2007 07:42 AM
How to collect values? kirks PHP How-To 1 August 28th, 2006 01:12 AM
Collect database space used and generate a report lixiay99 SQL Server 2000 2 May 9th, 2006 06:14 PM
page level NTFM auth - gives loss of form collect nickc001 Classic ASP Professional 0 November 26th, 2003 12:22 PM
How do I collect windows log on tray Javascript How-To 2 September 3rd, 2003 02:53 AM





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