Return ID from a select

M

Mark

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
 
G

Guest

Select Booking_Master.bookingID From BOOKING_MASTER WHERE BOOKING_NUMBER =
@Booking_Number"
Cmd.Parameters("@Booking_Number") = 1

and use cmd.ExecuteScalar() method

regards,
Jignesh
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top