Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Structure a SELECT Statement 1

Status
Not open for further replies.

nimarii

MIS
Jan 26, 2004
213
US
Hello,

I'm having some problems creating a SELECT statement in my C# app.

Here's what I have so far:
Code:
SELECT bill_no FROM voice_main WHERE beg_stamp > convert(datetime,StartDateTbx.Text) AND end_stamp < convert(datetime, EndDateTbx.Text)";

StartDateTbx & EndDateTbx are both textboxes on the webform.

the error message i'm getting is:
Code:
The column prefix 'StartDateTbx' does not match with a table name or alias name used in the query. The column prefix 'EndDateTbx' does not match with a table name or alias name used in the query.

How do I reference these textboxes containing date information in the SQL statement?
 
Try this:

"SELECT bill_no FROM voice_main WHERE beg_stamp > convert(datetime, " + StartDateTbx.Text + ")AND end_stamp < convert(datetime," + EndDateTbx.Text + ")";
 
Hi, thanks for the reply!

Here's the error message I get when using that:

Code:
c:\inetpub\[URL unfurl="true"]wwwroot\evisionwww\Views\Home\Pages\Reports.aspx.cs(76):[/URL] The type or namespace name 'StartDateTbx' could not be found (are you missing a using directive or an assembly reference?)

I think this could be a problem, since StartDateTbx is a textbox on the webform, but its contained within a usercontrol...

is there a way I can reference this control, or do I have to take a different approach to this?
 
The place where your SQL code is running will need access to the data contained in the control. So you'll need to pass it in as a parameter.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
I don't believe there is a way to reference the object that way. There may be, however, this defeats the whole purpose of user controls. User controls are supposed to be independent of any page.
You may have to pass the object to the usercontrol for you to use it, or you can just pass the text value.
 
Thanks, I'm new at this, so its still a huge learning process for me.

How can I pass the parameters from the usercontrol to the webform, or do I need to open up the connection within the usercontrol?

I'm worried that I've just simply designed this too poorly for anything to work effectively....
 
Where is the code above being called? Are you clicking a button on the webform or the UC?
 
I'm clicking a button on the webform itself...do i need to move the button to the UC?
 
Ok, so what is in the user control? what controls what code? I an just not getting what is where and why.

 
The UC contains 4 fields: StartDateTbx, EndDateTbx, StartTimeDdlb, EndTimeDdlb. This UC also contains another UC which causes a pop-up calendar to open up, and is how the user populates the StartDateTbx & EndDateTbx fields.

The webform has this main UC, and then a button called "Populate Toll Free Numbers" followed by a dropdownlistbox, and another button called "Generate Report".

The "Populate Toll Free Numbers" button needs to populate the dropdownlistbox depending on the data contained in the UC (in order to generate the SQL Statement).

I know this is confusing - any suggesstions are completely welcome...
 
I was able to get the value in a textbox in the UC with this code. Remember this is VB code:
Code:
CType(Me.Page.FindControl("txtTest"), TextBox).Text
 
I think this is the correct C# code

Code:
((TextBox)(this.Page.FindControl("txtTest"))).Text();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top