View Single Post
Old 12-07-2008, 10:21 PM   #1 (permalink)
StevenF
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default Query With a C# Variable?‏

Hiya


I was wondering if someone could help me out here, please? Big Smile

I'm creating a forum, my threads page has the following query:

SELECT * FROM [threads] WHERE ([forum_name] = ?) ORDER BY [time_created] DESC

The "?" (control value) is the sub-forum which the thread is linked to. Example:

List of Forums:

- Introduce Yourself
- The Lounge
- Another Thread
- Blah Blah Blah

User clicks on The Lounge, loads thread.aspx where Query: SELECT * FROM [threads] WHERE ([forum_name] = ?) ORDER BY [time_created] DESC runs

------------------------------------------------------------------------------------------------------------------------------------------------

Now the page with "The Lounge" threads loads, and I store the querystring into a variable

string forum_name = Page.Request.QueryString["forum_name"];
Page.Response.Write("Now browsing the threads about " + forum_name);

Now the user clicks "New Thread" button, and is presented with a form to fill out. Instead of typing the name of the forum that their thread is to be featured in (i.e. "The Lounge") I would like it to automatically have this filled in, based upon where they came from.

My Insert query then looks like this:

Insert Into threads ([thread_name], [thread_author], [forum_name], [time_created]) Values(?,?,?,?)"

But I'm getting an error saying "No value given for one or more required parameters." So I think the variable isn't passing into the query. Do you know why this might be?

Basically, how do I incorporate the value stored in that variable, into the query?


Thanks a lot!

Kind Regards,
Steven
__________________
My Personal and Photo Blog
StevenF is offline  
Reply With Quote