DataSource Controls :: Unable To Use Querystring In SQL Query
Apr 19, 2010
I'm passing on two Querystrings "ddl2" and "ddl3" onto an aspx page. At this page I'm running a SQL Query which has a WHERE clause in it that SHOULD use both the querystrings but only one of the two QS works at a time. When I use only "ddl2" OR only "dd3" in the WHERE clause the result is shown but not when both the Querystrings are used.
Below is the link to the page i get where I use the two QS's.
~/Option1_result.aspx?ddl2=722&%20ddl3=CA
Below is my SQL code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Inventory_DBConnectionString3 %>"
SelectCommand="SELECT * FROM [CA] WHERE (([LATA] = @LATA) AND ([State] = @State))">
<SelectParameters>
<asp:QueryStringParameter Name="LATA" QueryStringField="ddl2" Type="Int16" />
<asp:QueryStringParameter Name="State" QueryStringField="ddl3" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
View 2 Replies
Similar Messages:
Jan 20, 2010
i have a query like this and its running correctly
SELECT CAST(REPLACE(LTRIM(RTRIM(SUBSTRING(P.Telephone, 2, LEN(P.Telephone)))), ' ', '') AS BIGINT)
FROM P INNER JOIN PCommunication ON P.ID = PCommunication.ID
WHERE P.Telephone IS NOT NULL AND CAST(REPLACE(LTRIM(RTRIM(SUBSTRING(P.Telephone, 2, LEN(P.Telephone)))), ' ', '') AS BIGINT) > 5000000000
AND PCommunication.TypesID = '7667d187-5fe1-4aaf-9e31-79761561da58'
i am trying to use it with dynamic query like this but its not working
@query = 'SELECT CAST(REPLACE(LTRIM(RTRIM(SUBSTRING(P.Telephone, 2, LEN(P.Telephone)))), ''' ''', '''''') AS BIGINT)
View 9 Replies
Jun 27, 2010
im creating a photo album just like facebook album featureThe problem im facing now is unable to add new picture to a particular albumBelow is the code to pass a querystring to the addphoto.aspx in a datalist, i bind the sqldatasource using vb in the codebehind
[Code]....
[Code]....
View 5 Replies
Aug 22, 2010
1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like
SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.
Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).
2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query
(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).
If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.
View 11 Replies
Jan 15, 2010
[code]...
This query works perfectly on the query analyser.
But when configuring the Table adapter ,I try executing the query and i get 0 rows affected.
What could I be getting wrong in this case.
NB:Existing GalleryID has been supplied.
View 1 Replies
May 17, 2010
By right clicking on my database i created a query in server explorer. But where are this query stored can't find them back. I should aspect that their is a folder query's like there is a folder tables but this isn't the case.
View 10 Replies
Mar 10, 2010
select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid
View 5 Replies
Jan 21, 2010
I've got a query such as
Dim MediaQuery =
From m
In dB.DOWNLOADS _Where m.ID = id _Select
which returns a record from the database. One of the fields in the record is a FK to another table. I need to read this value to be able to set a dropdown based on the ID but I can't work out how to access it. For a standard record I can just do the following txtTitle.Text = MediaQuery.FirstOrDefault().TITLE
However with the foreign key it doesn't work like that. I've tried drpGroup.SelectedIndex = MediaQuery.FirstOrDefault().DOWNLOAD_GROUPS.ID where DOWNLOAD_GROUPS is the FK field but it returns Object reference not set to an instance of an object. If you're simply wanting to read some values from a single db record in the entitiy framework and one is a foreign key how should I go about getting the value?
View 2 Replies
Sep 23, 2010
I have an ODS control populating a Telerik grid. The ODS definition is pretty simple. It's set to call a method on a static class that has one parameter (entityID). I set this parameter in the OnSelecting event. When I test this, the world is a happy place and all is fine.
Then, I pass a query string to the page (which sets various unrelated values for the page, we'll say parameters X and Y). The page call's Telerik's radgrid.Rebind() event. When this happens, an error is throw from the ODS saying that the underlying method (the static data procedure) does not support parameters X and Y.
So, why is ODS thinking it should be using any querystring values at all when I have explicitly set the entityID parameter (of type Asp:Parameter)? How do I stop this from happening?
The Html:
[Code]....
The OnSelecting:
[Code]....
I see this odsList_OnSelecting being hit and the inspection of e.InputParameters only contains my expected single entry.
View 4 Replies
Mar 5, 2011
I have a small problem with a querystring that populates 4 dropdowns.
On page A I have a hyperlink that adds 4 values to my url and on page B I have 4 dropdowns. I am able to click the link and the dropdowns are populated with the correct data! My problem is I do not know how to fire the postback event from DDL4 that shows my data!
[Code]....
My Sql statement:
[Code]....
As you can see from my code there are 2 control parameters. When DDLPrice is selected my page shows all the data. But when I use the querystring method it does not.
I load the querystring from my page load event
[Code]....
View 2 Replies
Jun 29, 2010
this has to be a simple thing but I am missing it
here's what i have
the null condition and query works
the not null condition does not
I have tried:
ImageID=@id error myust declare @id
ImageID=id invalid column id
ImageID=?id incorrect syntax at ?
all errors occur at SqlDataReader Dr = Cmd.ExecuteReader();
int id = Convert.ToInt32(Request.QueryString["id"]);
string SQLquery ="";
if (id == null)
{
SQLquery = "Select Top 1 ImageData,ImageType from WebBGImages ORDER BY NEWID()";
}
else
{
SQLquery = "Select ImageData,ImageType from WebBGImages where ImageID=@id";
}
SqlCommand Cmd = new SqlCommand(SQLquery, connection);
SqlDataReader Dr = Cmd.ExecuteReader();
View 1 Replies
Jun 8, 2010
I have a simple page that will display data from a particular category, using a querystring to filter my data in my sql select statement.
However, I would like to show all my data if there is no querystring present. Is there a simple way to do this?
View 6 Replies
Apr 2, 2010
I have a page with a gridview that is populated depending upon the value of the querystring passed to it - there is a one-to-many relationship between Jobs and Locations respectively (one job can have many locations), and the gridview is a list of Locations that are associated with a particular Job. So far so good.
I have a DetailsView below whose DefaultMode is Insert to add a new location, though I can't seem to capture the JobId (guid) from the querystring. I've tried the following code on the Datasource's Inserting event:
[Code]....
but on both occasions I get the same error: Foreign Key constraint broken on JobId field. It seems that the querystring is not being passed to the datasource for inclusion in the insert.
View 2 Replies
Aug 7, 2010
I need to get a querystring in a select parameter
datasource.selectparameters.add("PostId", request.querystring("PostId"))
Something like that...but...i cant get the snytax right.
View 3 Replies
Feb 7, 2010
.cs code is
[Code]....
and .aspx code is
[Code]....
now i want to pass value in Reply.aspx?C={0} to stored procedure
View 3 Replies
Apr 23, 2010
I have an SQLSiteMapProvider that needs a unique URL and have not got the smarts to work out how to get the provider to do the work so for now I thought I would just add the data to the DB then edit the URL with the ID. I can't do this on the first insert as I do not know the ID as it is an auto generated Primary Key
I tried to us the PostBackURL to go to a 2nd Page that got the New ID and added it to the end of the already known URL "Page.aspx?ID=" but apparently you can't do that as I found out (This would have been a masive hack to the problem I know but it would have got around it issue of for now)
this is how I guessed it would work
Insert Data with URL "Page.aspx?ID=" and more data.... Then Get New ID and update URL to have the ID on the end ie: Page.aspx?ID=99
View 7 Replies
Jan 7, 2011
I have a question related to <asp:SqlDataSource's SelectCommand. How to pass a querystring like <%# Eval("PhotoID") %> in the selectCommand. The whole frontend code is attached. I put
<%# Eval("PhotoID") %> and the photoid gets printed in the page.
<%# Eval("PhotoID") %> is the current displayed picture's PhotoID.
I want to pass this PhotoID or I want to pass <%# Eval("PhotoID") %> to the select command dynamically. I have tried the following approaches:
1) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = @pID"> <SelectParameters><asp:Parameter Name="pID" DefaultValue="7" /></SelectParameters> </asp:SqlDataSource> The above works but it gives only information about PhotoID 7, but there are other photos; How to set pID's value to <%# Eval("PhotoID") %> in ASP .NET's frontend page? then I also tried,
2) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = <%#'Eval("PhotoID') %>"></asp:SqlDataSource> Gives Parser error: Parser Error Message: The server tag is not well formed.
What I should do so that I can pass current PhotoID to SelectCommand? The frontend code:
<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Your Name Here | Picture Details"
CodeFile="Details.aspx.vb" Inherits="Details_aspx" %>
<asp:content id="Content1" contentplaceholderid="Main" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="shim solid"></div>
<div class="page" id="details">
<%--Update Panel Here--%>
<asp:UpdatePanel runat="server" ID="updatepanel">
<ContentTemplate>
<asp:formview id="FormView1" runat="server" datasourceid="ObjectDataSource1" cssclass="view"
borderstyle="none" borderwidth="0" CellPadding="0" cellspacing="0" EnableViewState="false" AllowPaging="true">
<itemtemplate>
<div class="buttonbar buttonbar-top">
<a href="Albums.aspx"><asp:image ID="Image1" runat="Server" skinid="gallery" /></a>
<asp:ImageButton ID="ImageButton9" Runat="server" CommandName="Page" CommandArgument="First" skinid="first"/>
<asp:ImageButton ID="ImageButton10" Runat="server" CommandName="Page" CommandArgument="Prev" skinid="prev"/>
<asp:ImageButton ID="ImageButton11" Runat="server" CommandName="Page" CommandArgument="Next" skinid="next"/>.................
View 14 Replies
Jan 21, 2010
after I pass querystring parameter to page,page works as expected,but after that when I change my control parameter(dropdownlist selected value how can I set querystring to null or empty...
View 1 Replies
Feb 8, 2010
I found this function on [URL] It works great and I can get the properties and display them in separate binds. This is how I call the function, as shown In the link above
SELECT userid, username,
dbo.aspnet_Profile_GetProfile(userid, 'FirstName', DEFAULT) AS FirstName,
dbo.aspnet_Profile_GetProfile(userid, 'LastName', DEFAULT) AS LastName
FROM aspnet_users
However, i cant get it to work with a simple querystring...
<SelectParameters>
<asp:QueryStringParameter Name="username" QueryStringField="user" Type="String" />
</SelectParameters>
I want to fetch a users First and last name with a querystring, for example (default.aspx?user=DemoUser) But it doesn't work, it displays the latest entry in the aspnet_profile table. Btw, im trying to display it in a formview.
View 3 Replies
Jul 7, 2010
I have trouble getting hold of the UserName from the QueryString. My data is not displayed on my page.
What is the problem with this code:
[Code]....
View 7 Replies
Aug 6, 2010
I've got an issue with the postback property. I have a chart (Code below) which has two series pulled from a datasource.
Both series display fine but I've enabled the bars in the chart to respond to the click event and when items from the first series is selected, everything works fine. However, I try to pull the x value for the second series, which is supposed to be a date, but all I get is an interger.
[Code]....
C# Code...
[Code]....
View 1 Replies
May 7, 2015
The following code works well as long as I pass a querystring value to the datalist.
Private Sub BindGrid()
Dim id As Integer = Integer.Parse(Context.Request.QueryString("id"))
Dim strConnString As String = ConfigurationManager.ConnectionStrings("Conn").ConnectionString
Using con As New SqlConnection(strConnString)
Using cmd As New SqlCommand()
cmd.CommandText = "select Id, Name from tblFiles where Id=@Id"
[Code] ......
However, the page errors with the message "Value cannot be null." if I don't pass a value. I know that DataList does not have an EmptyItem Property like a Gridview control. I do not want the page to error if I don't pass a value. Need info to deal with empty values in a datalist.
Most websites have pointed me to this code to use:
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="No Result" runat="server"
Visible='<%#boolean.parse(([b]list[/b].Items.Count=0).ToString())%>'>
</asp:Label>
</FooterTemplate>
The 'list' throws an error. The error is "Too few type arguments to 'System.COllections.Generic.List". I am not sure if the code is written in C# and that is what is causing the error. It seems that it should work but I can not figure out the 'list' error.
View 1 Replies
May 29, 2010
I need to check if any rows are returned in a QueryString here's what I have so far.not sure what code to put to see if the row count is greater than 1
private void BindDataToGrid()
{
//MessageBoardEntities3 is ThemeableAttribute connection string name
int TID = Convert.ToInt32(Request.QueryString["ThreadID"].ToString()); // if Post ID is int
var context = new MessageBoardEntities3();
gvPosts.DataSource = from p in context.Posts
where p.ThreadID == TID
select new { p.Post1, p.PostID };
gvPosts.DataBind();
lblNoPosts.Text = "No posts found for this thread.";
}
View 1 Replies
Apr 21, 2010
I am using Querystring "ddl4" to pass on value of a drop down list to the next page where I am using that value in the WHERE clause of a SQL command. I also need to check whether ddl4 is blank or not which I do using If Else in SQL command. I am not able to run the query where the Querystring ddl4 IS NULL
This is the sample link with the Querystring ddl4 carrying a blank value:
[code]....
View 2 Replies
May 13, 2010
My pages work with a SqlDataSource and an Access Database but returns an error when I'm using a SQL Server database.
ERROR [42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'sid'
[Code]....
View 12 Replies