Showing posts with label buttons. Show all posts
Showing posts with label buttons. Show all posts

Sunday, February 19, 2012

How to use a variable in a SQL statement…

Hi,

background

From a 'members' table, I get the first letter of the last name of the members and display in a dataList as buttons.

In the dataList control, the

<asp:button>
has the following:
CommandArgument='<%# DataBinder.Eval(...) %>' OnCommand="doSomething"

In the code behind page I have the following code:


Public Sub doSomething(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
Dim getLastName as string = e.CommandArgument.ToString()
lblBtn.Text = "clicked " + e.CommandArgument.ToString()
…

This code will do the job – in the label 'lblBtn' the text will show the 'value' that the button represents – i.e. if you click the button for 'B' the lblBtn will read 'clicked B'

The problem

Now that I know which button was clicked, I need to use the information in a SQL query to retrieve the relevant data.


Const strSQL2 As String = "select * from members where letter = 'getLastName'"

This query returns no records at all – no errors, just nothing. What I am doing wrong?

Kindly help.

Thanks,

Sami.a couple of questions:
1> Is the first letter of the last name stored in Members under field letter?
2> Is the following statement used in doSomething?


Const strSQL2 As String = "select * from members where letter = 'getLastName'"

If the answer to both questions are YES. Here is your correct strSQL2:


Const strSQL2 As String = "select * from members where letter = '" & getLastName & "'"
|||Thanks for your response – yes, you are right on both assumptions. I did what you suggested but got an error.

In VS the expression 'getLastName' got a blue underline and when I mouse over it I get a balloon message that says 'Constant expression is required'

When I 'view in browser' and click 'yes' for continuing with the preview and then click on one of the letter buttons I get an error page with the following message:

Incorrect syntax near '='

Any suggestions?

Thanks for your patience - I am very new at this

Sami.|||Sorry. My fault. Overlooked your statement. Please remove "Const " from your statement below.


Const strSQL2 As String = "select * from members where letter = 'getLastName'"


Change to this:


strSQL2 As String = "select * from members where letter = 'getLastName'"

Please let me know if there is still error.|||Wow - thank you so much...

It works great.

Sami.

How to use a checkbox for Boolean Report Parameter?

All booleans values that I set inside the report parameters show up as true/false radio buttons on the report. Is there anyway to make these checkboxes instead of radio buttons?

You can convert radiobuttons to dropdown by specifying available values "true" and "false"

To get checkboxes you could use String or Integer parameter instead of Boolean

|||

Can you explain,I tried this option it is not working. I create a Sp,it accepts 1 or 0 as input parameter.

Thanks,

Prabu

|||

In the available values grid enter two rows:

1st: set label to True, value to 1

2nd: label to False, value to 0

|||

It would be a nice feature in further releases: Show a single checkbox for a boolean instead of two radiobuttons. Then unchecked would be false and checked would be true.

It would also be nice to define the default return value ... now the radiobutton (true) returns true. (Well it makes sence but sometimes its usefull to turn it around and keep the radiobuttons)

How to use a checkbox for Boolean Report Parameter?

All booleans values that I set inside the report parameters show up as true/false radio buttons on the report. Is there anyway to make these checkboxes instead of radio buttons?

You can convert radiobuttons to dropdown by specifying available values "true" and "false"

To get checkboxes you could use String or Integer parameter instead of Boolean

|||

Can you explain,I tried this option it is not working. I create a Sp,it accepts 1 or 0 as input parameter.

Thanks,

Prabu

|||

In the available values grid enter two rows:

1st: set label to True, value to 1

2nd: label to False, value to 0

|||

It would be a nice feature in further releases: Show a single checkbox for a boolean instead of two radiobuttons. Then unchecked would be false and checked would be true.

It would also be nice to define the default return value ... now the radiobutton (true) returns true. (Well it makes sence but sometimes its usefull to turn it around and keep the radiobuttons)