Solved

how to pass a textbox value to a gridview selectcommand

Posted on 2009-04-10
3
1,285 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now