Is Possible to put some server tag in Session Field to access a constant string???
<asp:EntityDataSource ID="EntityDataSourceProcesos" runat="server" ConnectionString="name=Entities"
DefaultContainerName="Entities" EntitySetName="PROCESO" EntityTypeFilter="PROCESO"
Select="it.[DE_PROC], it.[ID_PROC], it.[ST_PROC]"
Where="it.[ST_PROC] = 1 and it.[TMEMPR].[CO_EMPR] = #EmpresaID">
<WhereParameters>
<asp:SessionParameter Name="EmpresaID" SessionField='<%= stringPublicVariable %>' Type="String" />
</WhereParameters>
</asp:EntityDataSource>
Instead you can add your parameter at code behind :
EntityDataSourceProcesos.WhereParameters.Add(
new SessionParameter("EmpresaID", TypeCode.String, stringPublicVariable));
Related
i'm working on asp project and i want to use commandparameters
my question is how to put the value of controlid by using url parameter
i try this but doesnt working
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=DentistEntities" DefaultContainerName="DentistEntities" CommandText="SELECT p.[id],p.[firstName],p.[lastName],p.[DOB],p.[firstVisiting] FROM DentistEntities.Patients AS p WHERE p.[firstName]=#firstname">
<CommandParameters>
<asp:ControlParameter Name="firstname" ControlID='<% Request.QueryString["firstName"] %>' Type="String"/>
</CommandParameters>
</asp:EntityDataSource>
error on page
Could not find control '<% Request.QueryString["firstName"] %>' in ControlParameter 'firstname'.
There is a special QueryStringParameter for that:
<asp:QueryStringParameter Name="firstname" QueryStringField="firstName" Type="String"/>
I have an entity datasource and i would like to filter it (created_on) to show only the max date. How do i go about doing it?
<asp:EntityDataSource ID="Payroll_DetailsDS" runat="server"
ConnectionString="name=sspEntities" DefaultContainerName="sspEntities"
EnableDelete="True" EnableFlattening="False" EnableInsert="True"
EnableUpdate="True" EntitySetName="Payroll_Details"
OrderBy="it.[Payslip_no] desc" EntityTypeFilter="" Select=""
Where="it.Status = "COM"">
</asp:EntityDataSource>
Right now the data source is only filtering by it.status. I would to filter also by it.created_on = Max(created_On) .. thats the idea of what i want, dont know how to get it.
i was able to get something similar in linq and it worked fine. just need it in entity datasource.
var testquery = from d in context.Payroll_Details
where d.Created_on == ((from b in context.Payroll_Details
where b.Employee_Personal_InfoEmp_id == xyz.PD_EmpPersonal_Id
select b.Created_on).Max())
select new
{
d.Employee_Personal_InfoEmp_id,
d.Basic_Pay_YTD
};
var r = testquery.SingleOrDefault();
If I undertand you right, you can use this way:
<asp:EntityDataSource ID="SalesOrderHeader" runat="server"
ConnectionString="name=AdventureWorksEntities"
DefaultContainerName="AdventureWorksEntities" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" EntitySetName="SalesOrderHeader"
EntityTypeFilter="" OrderBy="it.TotalDue DESC" Select=""
Where="it.OnlineOrderFlag = TRUE AND it.TotalDue > #ordercost">
<WhereParameters>
<asp:ControlParameter ControlID="costLimit" DbType="Int32"
DefaultValue="2500" Name="ordercost" PropertyName="Text" />
</WhereParameters>
</asp:EntityDataSource>
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.entitydatasource.orderby.aspx
I am new to asp.net and i have a problem using a dropdownlist control inside a formview and passing its value to the related sqldatasource. When i use the code below i get the following exception
Exception Details: System.InvalidOperationException: Could not find control 'ddlCategory' in ControlParameter 'categoryId'.
The Dropdownlist inside a formview.
<asp:DropDownList ID="ddlCategory" DataSourceID="ObjectDataSourceCategory" DataTextField="NAME" DataValueField="ID" runat="server" />
The SQL Data Source
<asp:ObjectDataSource ID="sqlDataSourceItem" TypeName="Item" runat="server"
SelectMethod="getItem"
InsertMethod="insertItem"
UpdateMethod="updateItem">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="id" Name="id" />
</SelectParameters>
<InsertParameters>
<asp:ControlParameter ControlID="ddlCategory" Name="categoryId" PropertyName="selectedValue" />
</InsertParameters>
</asp:ObjectDataSource>
And i have found the solution to this problem. I have changed the ID of the DDL in the control parameter. It works like below since this is the final generated id of that control. But i think there must be an easier and better way. Any help would be appriciated.
<asp:ControlParameter ControlID="ctl00$main$frmViewItem$ddlCategory" Name="categoryId" PropertyName="selectedValue" />
This answer will provide a solution to your problem:
You need a recursive findcontrol() method.
It is because of your ddlCategory is inside formview and you are using the master page. The best way is to overwrite the 'FindControl' function of master page.
pls see the following link for detail:
http://geekswithblogs.net/AzamSharp/archive/2006/08/27/89475.aspx
I'm trying to create simple search. I have "txtSearch" textBox and "search" button in MasterPage, button has PostbackUrl= Search.aspx
In MasterPage
<asp:TextBox ID="txtSearch" runat="server" ValidationGroup="b" Text="Users Search" ForeColor="Silver">Users Search</asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" ValidationGroup="b"
PostBackUrl="~/Search.aspx" onclick="btnSearch_Click" />
In Search.aspx i have GridView that shows me results and SqlDataSource
<asp:SqlDataSource ID="SqlDataSearchResult" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT vw_aspnet_Users.UserId, vw_aspnet_Users.UserName, Custon_UserInfo.UserId AS Expr1, Custon_UserInfo.FirstName, Custon_UserInfo.LastName, Custon_UserInfo.Location, Custon_UserInfo.Avatar, Custon_MoneyWork.UserId AS Expr2, Custon_MoneyWork.Money, vw_aspnet_Users.LastActivityDate FROM vw_aspnet_Users INNER JOIN Custon_UserInfo ON vw_aspnet_Users.UserId = Custon_UserInfo.UserId INNER JOIN Custon_MoneyWork ON vw_aspnet_Users.UserId = Custon_MoneyWork.UserId WHERE (vw_aspnet_Users.UserName LIKE '%' + #UserName + '%')">
<SelectParameters>
<asp:FormParameter FormField="txtSearch" Name="UserName" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
In Define Parameters :
UserName =Request.Form("txtSearch") as it needs to be, but it's not working. I tried with session["search"]=txtSearch.text; and its working.. But not with Request.Form..
UPD
I tryed to use QueryStringField instead of FormField and it works, don't know whats wrong with FormField.
Why not avoid Session variables (I don't like the idea of a 'global' variable that sits above everything else, and no way of knowing if it was inadvertently changed or corrupted by bad code, for example), and use ControlParameter instead?
ie
<SelectParameters>
<asp:ControlParameter ControlID="txtSearch" Name="UserName" PropertyName="Text" Type="String" />
</SelectParameters>
Let ASP.net do most of the work for you.
How can I execute a stored procedure using sqldatasource and get the return value in vb.net.
Thanks,
Terri
The method you are looking for is DataBind. Call it using mySqlDataSource.DataBind()
<asp:SqlDataSource
ID="sds2"
runat="server"
ConnectionString="..."
SelectCommand="spTest"
SelectCommandType="StoredProcedure"
>
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" PropertyName="Text"
Name="ParamName" Type="Int32" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="gv" runat="server" DataSourceID="sds2"></asp:GridView>
The stored procedure is executed when you call DataBind. The DataBind method is called automatically if the DataSourceID property of the GridView control refers to a valid data source control.
You need to use a SqlConnection with a SqlCommand, like this:
using (var connection = new SqlConnection(connectionString))
using (var command = new SqlCommand("StoredProcedureName", connection)) {
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("SomeParam", someValue);
object result = command.ExecuteScalar();
}
If you already have the SP returning a value then you have to grab the value in the corresponding event for the data source. AKA - Inserted, Selected, etc...
Here's a couple links illustrating the point.
http://fredrik.nsquared2.com/viewpost.aspx?PostID=162
http://www.velocityreviews.com/forums/t86158-re-how-to-retrieve-an-output-parameter-using-sqldatasource-control.html
<asp:SqlDataSource ID="ADSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ADConnection %>"
SelectCommand="GetProfile" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="InputTextBox" Name="Host" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
GetProfile is the stored proc name and Host is parameter name, which is retreived from a texbox called InputTextBox