Coding help needed.

  • Thread starter Thread starter Angelina
  • Start date Start date
A

Angelina

Hi,

I need help on trying to figure out the best way to solve
this problem.

What i have is a combobox that allows the user to select
a room they want. A stored procedure is run once a room
is selected that should return a boolean value stating
wether the room supplies catering. Based on this boolean
value a groupbox is displayed. i.e if the value is false,
the groupbox should be hidden. The groupbox should only
be displayed if the value is false.

How do i go about doing this?

This is my sproc..
SELECT Catering
FROM dbo.Rooms_avail
WHERE (Room_name = @RoomName)

This is my code so far...
Dim Cn As New SqlConnection("initial
catalog=TestCaraDBmsde;integrated security=SSPI;persist
security info=False;workstation id=USER;packet size=4096")

Dim cmdCatering As New SqlCommand("SPSelCatering", Cn)
cmdCatering.CommandType = CommandType.StoredProcedure

'declare the parameters
cmdCatering.Parameters.Add("@RoomName", SqlDbType.Char,
50)

'now set the values
cmdCatering.Parameters("@RoomName").Value =
CBoxRoomNames.SelectedItem



can anyone please help me finish this up?

thx in advance
 
Angelina said:
Hi,

I need help on trying to figure out the best way to solve
this problem.

What i have is a combobox that allows the user to select
a room they want. A stored procedure is run once a room
is selected that should return a boolean value stating
wether the room supplies catering. Based on this boolean
value a groupbox is displayed. i.e if the value is false,
the groupbox should be hidden. The groupbox should only
be displayed if the value is false.

How do i go about doing this?

This is my sproc..
SELECT Catering
FROM dbo.Rooms_avail
WHERE (Room_name = @RoomName)

This is my code so far...
Dim Cn As New SqlConnection("initial
catalog=TestCaraDBmsde;integrated security=SSPI;persist
security info=False;workstation id=USER;packet size=4096")

Dim cmdCatering As New SqlCommand("SPSelCatering", Cn)
cmdCatering.CommandType = CommandType.StoredProcedure

'declare the parameters
cmdCatering.Parameters.Add("@RoomName", SqlDbType.Char,
50)

'now set the values
cmdCatering.Parameters("@RoomName").Value =
CBoxRoomNames.SelectedItem



can anyone please help me finish this up?

Looks like that procedure returns a resultset with one row and one columne.

You can use

Catering = cmdCatering.ExecuteScalar()

which is just shorthand for
Dim dr as SqlDataReader = cmdCatering.ExecuteReader()
try
dr.Read()
Catering = dr(0)
finally
dr.Close()
end try

David
 
Hi David,

Thx so much for your help. It seems to be working now.
:o)
is the execute reader only used when one value is being
returned. I read abit about it but im still kinda
confused as to its function.

thx for your time.
 
Hi Angelina,

Angelina said:
Hi David,

Thx so much for your help. It seems to be working now.
:o)
is the execute reader only used when one value is being
returned. I read abit about it but im still kinda
confused as to its function.

You mean ExecuteScalar() probably. Yes, it only returns the first value in
first row.
 
Back
Top