I have a page 3 datacontrols (in order, datalist->grid->listview, the selection from one feeds into the next) works perfectly locally, using dot net connector for mysql. My webhost uses ODBC, and I had to remove [ ] from the select statements in my code and put the table names. I removed the [ ] 's and my page runs, and my 1st/datalist control shows but now my "selected value" of my datalist, doesn't populate my grid control.
I imagine theres another peculiarity with the way odbc handles parameters.
Here is my original, for my grid:
<asp:SqlDataSource ID="recipegrid" runat="server"
ConnectionString="<%$ ConnectionStrings:exoticingConnectionString %>"
ProviderName="<%$ ConnectionStrings:exoticingConnectionString.ProviderName %>"
SelectCommand="SELECT [Id], [Name], [Cal], [Pro], [Fat], [Carb], [Fiber], [Chol], [Sod] FROM [tblrecipes] WHERE ([filenameid] = #filenameid) ORDER BY [name]">
<SelectParameters>
<asp:ControlParameter ControlID="DataList1" Name="filenameid"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
example of changes to select that allowed my page to run again:
SelectCommand="SELECT tblrecipes.Id, tblrecipes.Name, tblrecipes.Cal, tblrecipes.Pro, tblrecipes.Fat, tblrecipes.Carb, tblrecipes.Fiber, tblrecipes.Chol, tblrecipes.Sod FROM tblrecipes WHERE tblrecipes.filenameid = #filenameid ORDER BY tblrecipes.name">
BTW,
I also tried removing my scriptmanager & updatepanel,, and using autopostbacks instead in my controls, jik, and nothing changed so I put it back.
changed :
WHERE ([filenameid] = #filenameid)
to:
WHERE ([filenameid] = ?)
and it worked
Related
I have a drop down list that bound to a SqlDataSource.
I have another drop down list that's bound to a different SqlDataSource.
The second SqlDataSource has the first drop down as a Control Parameter.
I'm trying to do this...
<asp:SqlDataSource ID="sqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM Test WHERE Param = #param;"
CancelSelectOnNullParameter="true">
<SelectParameters>
<asp:ControlParameter ControlID="dropDown1" Name="param"
PropertyName="SelectedValue"
ConvertEmptyStringToNull="true" />
</SelectParameters>
</asp:SqlDataSource>
dropDown1.SelectedValue = "someValue"
dropDown2.DataBind()
but I don't get any results. However, if I set the second SqlDataSource's Control Parameter to a text box, it works. For example, this works:
<asp:ControlParameter ControlID="txt" Name="param"
PropertyName="Text"
ConvertEmptyStringToNull="true" />
txt.Text = "someValue"
dropDown2.DataBind()
Any ideas why this is?
I ended up figuring this one out. The problem was that the drop down was attempting to bind twice, much like the problem in this question.
I used the suggestion made by Joel Etherton, and now it works perfectly. Although I used a hidden control rather than a label.
I'm trying to use a asp:SqlDataSource driven by a SQL Select with Arguments. It works as long as I don't have any arguments. I can run the parameterized query via studio and it works and returns rows. If I any arguments, then the asp:View doesn't render.
First, the code returns 2 rows when I execute the SQL via Studio.
Second, I don't want it as a stored proc. Deployment issue. Smile, let it go. :-)
<asp:DropDownList ID="lstUsers" runat="server" DataSourceID="sqlGetCSGUsersOnClaim" DataTextField="username" DataValueField="userID" />
<asp:SqlDataSource ID="sqlGetCSGUsersOnClaim" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer%>" SelectCommandType="Text" SelectCommand="
SELECT aspnet_Users.UserId as userID, aspnet_users.username as username
FROM claims, aspnet_Users
WHERE claims.claimid = #ClaimID and
(Claims.AdjusterID = aspnet_Users.UserId or Claims.SupervisorID = aspnet_Users.UserId )">
<SelectParameters>
<asp:SessionParameter Name="ClaimID" SessionField="ClaimID" Type="Int32" DbType="Int32" />
</SelectParameters>
</asp:SqlDataSource>
If I remove the #ClaimID and SelectParameters arguments, the dropdown populates. It only fails once I add the parameter.
What am I doing wrong?
Thanks in advance,
Jason
Well it turned that if I removed the Type and DBType attributes of the SelectParameter, the code worked. sigh....
I have no idea, why though.
Hi I'm trying to get a filter expression working on my content column located in BLOG table on my gridview.
It displays the content column fine with 50 characters but when i try click my asp button to run the filter expression i get an error saying content column not found.
Any idea why this is?
Here's my code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Assignment2ConnectionString %>" SelectCommand="SELECT [blogid], [myfriendid], [inputdate],
Left(content,50) FROM [BLOG]" filterexpression="[content] LIKE '%{0}%' or url LIKE '%{0}%'">
<filterparameters>
<asp:controlparameter controlid="TextBox1" propertyname="Text" />
</filterparameters>
</asp:SqlDataSource>
When you do Left(content,50) that the column no longer has a name
Change the to this
ConnectionString = "<%$ ConnectionStrings:Assignment2ConnectionString %>"
selectCommand "SELECT [blogid], [myfriendid], [inputdate],
Left(content,50) AS ShortContent FROM [BLOG]"
filterexpression = "[ShortContent] LIKE '%{0}%' or url LIKE '%{0}%'">
I am quite new to asp.net,I am building an application where I need to show the in the grid view,Now the query I am generating for fetching the data from database containing one parameter which comes from the query string.I am using this code
<asp:SqlDataSource runat="server" ID="MySQLData"
ConnectionString="server=localhost;port=3309; User Id=xxxxx;password=xxxxx;database=xxxxx"
ProviderName="MySql.Data.MySqlClient"
SelectCommand="SELECT contenthead.lastmodifieddate,contenthead.heading,lk_technology.technology FROM contenthead JOIN lk_technology WHERE contenthead.techID=lk_technology.techID AND contenthead.authorid='<%=Request.QueryString["uid"]%>'" />
Now when I am using <%..%> tag I am getting parser error that says: Server tags cannot contain <% ... %> constructs.
Now I want to use this variable from query string.Please tell me how I can access this variable in this context.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..." ProviderName="System.Data.SqlClient" SelectCommand="SELECT [UserId], [LastUpdatedDate] FROM [vw_aspnet_Profiles] WHERE ([UserId] = #UserId)">
<SelectParameters>
<asp:QueryString ParameterDefaultValue="0" Name="UserId" QueryStringField="Id" Type="Object"/>
</SelectParameters>
</asp:SqlDataSource>
You have to add a parameter to your SqlDataSource
I have an ASP SqlDataSource connected to Sybase DB query, using Select Parameters that are populated by a dropdown:
Dropdown (works OK):
<asp:SqlDataSource ID="dsBondIDList" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [name], [bondID] FROM [bonds]">
</asp:SqlDataSource>
<asp:DropDownList ID="lstBondID" runat="server" DataSourceID="dsBondIDList" DataTextField="name" DataValueField="bondID">
SqlDataSource with parameter:
<asp:SqlDataSource ID="dsBonds" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [ticker], [name], [isin], [currency],
[stock], [maturity], [bid], [ask]
FROM [bonds] where [bondID] = #bondID">
<SelectParameters>
<asp:ControlParameter Name="bondID" ControlID="lstBondID" PropertyName="SelectedValue" DefaultValue="-1" />
</SelectParameters>
</asp:SqlDataSource>
But I get an error when I try to run it:
ERROR [HY000] [DataDirect][ODBC Sybase Wire Protocol driver][SQL Server]Must declare variable '#bondID'.
Which of course I would get it I ran the sql literally as displayed. I expect the ASP engine to do the substitution before sending the query (and to use the default value of lstBondID if necessary)
Does anybody know why the #bondID is not being substituted with the lstBondID.SelectedValue?
Thanks in advance
Ryan
I just went through this problem 10 minutes ago and here's the fix:
If you need to keep using the ODBC driver you have, change your query to use ? instead of Named Parameters.
SELECT [ticker], [name], [isin], [currency],
[stock], [maturity], [bid], [ask]
FROM [bonds] where [bondID] = ?
The parameters are used in the order they are added to the parameters collection (This gets hairy when you need to use the parameter more than once in your query etc).
Otherwise you can change drivers. Look for sybdrvodb.dll and regsvr32 it. Then setup your DSN and use that.