Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to pass a textbox value to a gridview selectcommand

Posted on 2009-04-10
3
Medium Priority
?
1,324 Views
Last Modified: 2012-05-06
I want to pass a value from a textbox to a gridview selectcommand....

See code below

<asp:TextBox CausesValidation="false" AutoPostBack="true" CssClass="textbox" ID="Date1" Width="150" runat="server" />&nbsp;
                
 
SelectCommand="SELECT [b_id], [epostID], [telefonID], [bokningsnr], [datum], [tidpunkt], [platser], [kommentar] FROM [bokningsDB] WHERE ([datum] = @Date1.Text)"

Open in new window

0
Comment
Question by:mattegol
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 2000 total points
ID: 24118319
Hi,

You need to pass it as a ControlParameter rather than trying to pass it declaratively, i.e.:

SelectCommand="SELECT [b_id], [epostID], [telefonID], [bokningsnr], [datum], [tidpunkt], [platser], [kommentar] FROM [bokningsDB] WHERE ([datum] = @Date)"

And then in the datasource declare:

        <SelectParameters>
            <asp:ControlParameter ControlID="Date1" ConvertEmptyStringToNull="true" DbType="Date" Name="@Date" PropertyName="Text" />
        </SelectParameters>

Hope this helps,

/Carl.
0
 

Author Comment

by:mattegol
ID: 24122873
I get this error with that:
Must declare the scalar variable "@Date".

I have a this updatecommand to:
UpdateCommand="UPDATE bokningsDB SET epostID = @epostID, telefonID = @telefonID, bokningsnr = @bokningsnr, datum = @datum, tidpunkt = @tidpunkt, kommentar = @kommentar  WHERE b_id = @b_id">
0
 

Author Closing Comment

by:mattegol
ID: 31569017
Thank you, this helped.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question