473,394 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Return ID from a select

Hi
I want to return the ID of a table based on a select
I've not tested the following code, does it look ok?
<code>
Dim Con As New SqlClient.SqlConnection

Con.ConnectionString =
ConfigurationSettings.AppSettings("ConnString")
Con.Open()
'generate select statement
Dim Cmd As New SqlClient.SqlCommand
Cmd.Connection = Con

Cmd.CommandType = CommandType.Text
Cmd.CommandText = "Select * From BOOKING_MASTER
WHERE BOOKING_NUMBER = @Booking_Number"
Cmd.Parameters("@Booking_Number") = 1

'return the Booking_Master.bookingID to a variable here
</Code>

can any one help with returning the ID and telling me if
the code looks ok?
Thanks
Mark
Nov 18 '05 #1
2 1026
Select Booking_Master.bookingID From BOOKING_MASTER WHERE BOOKING_NUMBER =
@Booking_Number"
Cmd.Parameters("@Booking_Number") = 1

and use cmd.ExecuteScalar() method

regards,
Jignesh

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:09****************************@phx.gbl...
Hi
I want to return the ID of a table based on a select
I've not tested the following code, does it look ok?
<code>
Dim Con As New SqlClient.SqlConnection

Con.ConnectionString =
ConfigurationSettings.AppSettings("ConnString")
Con.Open()
'generate select statement
Dim Cmd As New SqlClient.SqlCommand
Cmd.Connection = Con

Cmd.CommandType = CommandType.Text
Cmd.CommandText = "Select * From BOOKING_MASTER
WHERE BOOKING_NUMBER = @Booking_Number"
Cmd.Parameters("@Booking_Number") = 1

'return the Booking_Master.bookingID to a variable here
</Code>

can any one help with returning the ID and telling me if
the code looks ok?
Thanks
Mark

Nov 18 '05 #2
thanks
I'm getting the error
An SqlParameter with ParameterName '@Booking_Number' is
not contained by this SqlParameterCollection.

heres the code
Dim TCatCmd As New SqlClient.SqlCommand
TCatCmd.Connection = TcatCon
TCatCmd.CommandType = CommandType.Text
TCatCmd.CommandText = "Select
Booking_Master.bookingID From BOOKING_MASTER WHERE
BOOKING_NUMBER = @Booking_Number"
TCatCmd.Parameters("@Booking_Number").Value =
1000000735356

any ideas?
thanks
mark
-----Original Message-----
Select Booking_Master.bookingID From BOOKING_MASTER WHERE BOOKING_NUMBER =@Booking_Number"
Cmd.Parameters("@Booking_Number") = 1

and use cmd.ExecuteScalar() method

regards,
Jignesh

"Mark" <an*******@discussions.microsoft.com> wrote in messagenews:09****************************@phx.gbl...
Hi
I want to return the ID of a table based on a select
I've not tested the following code, does it look ok?
<code>
Dim Con As New SqlClient.SqlConnection

Con.ConnectionString =
ConfigurationSettings.AppSettings("ConnString")
Con.Open()
'generate select statement
Dim Cmd As New SqlClient.SqlCommand
Cmd.Connection = Con

Cmd.CommandType = CommandType.Text
Cmd.CommandText = "Select * From BOOKING_MASTER
WHERE BOOKING_NUMBER = @Booking_Number"
Cmd.Parameters("@Booking_Number") = 1

'return the Booking_Master.bookingID to a variable here
</Code>

can any one help with returning the ID and telling me if the code looks ok?
Thanks
Mark

.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Powell | last post by:
My first time working with a PHP class, and after 6 hours of working out the kinks I am unable to return a value from the class, so now I appeal to the general audience what on earth did I do wrong...
0
by: Jeff Mason | last post by:
Consider the following (questionable, to be sure, but syntactally legal) stored procedure (using the Northwind database): Create Procedure Test As Return (Select Count(*) From Orders) Select *...
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
2
by: thuythu | last post by:
Please help me.... I used and Javascript to view the data. But when i click button open a popup windows, then select data and click save button. The popup close and return the main page, but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.