Public Property as ObjectDataSource Select Parameter - asp.net-4.0

I have an ODS, which is bound to an ADO.NET datatable. There is one select parameter. I would like to use a public property which I have declared in my code-behind as the select parameter, something like:
<SelectParameters>
<asp:ControlParameter ControlID='<%# EInfoProperty %>' Name="quote_header_id"
PropertyName="headerId" Type="Int32" />
</SelectParameters>
The above syntax doesn't work, and I've been unable to find anything here, on MSDN or on Google that might help here. Is there a way to do this, or am I stuck sticking the value in the Session, or something?

From everything I could find, this is not currently possible. For my purposes, I ended up putting the value in question in the session and using a SessionParameter.

Related

NHibernate mapping customization

I'm using Nhibernate 3.3.1 and I need to ensure that none of my string columns would have lengths smaller than 15 i.e.
I'm trying to check it no AfterMapProperty/BeforeMapProperty events of ModelMapper, but as I know Length property is private of PropertyMapper class or some base class of it.
I'm tryign to avoid to use Reflection to access private property to get Length and check it.
Can you help me?
You can use the check attribute to achieve this.. In your mapping file you need to define something like this:
<property name="Foo" type="string">
<column name="foo" check="DATALENGTH(foo) > 15"/>
</property>
This will create a check constraint.. I am not too sure about the DATALENGTH method but you can confirm that..
Refer section 20.1.1 of NH docs here: http://nhibernate.info/doc/nh/en/index.html

Coldfusion, default ORM object?

so I have a form that I'm using for new items, and to edit items.
The input fields therefore may have a value or not. I'm using this code in the value field.
<input name="uuid" value="<cfif isNull(item.GetUuid())>#item.GetUuid()#</cfif>"/>
Is this the best way to do it? I would have thought the ORM returning a blank object or something maybe cleaner, but not sure of a tider way to do it?
This might work
<cfproperty name="uuid" default="">

GridView Updating on ItemCommand

i put all my custom "update" code in the RowCommand event, it works fine, but i still get an error from my Data Source
System.NotSupportedException: Updating
is not supported by ObjectDataSource
'GetSources' unless the UpdateMethod
is specified.
how can i get rid of that error , yes still use my custom update code on the rowcommand?
Well, I think the way the ObjectDataSource is intended to be used is you specify the name of the method in your custom business object, and it will use reflection to call that method.
So, your page and object might look something like this:
<asp:objectdatasource
id="ObjectDataSource2"
runat="server"
updatemethod="MyUpdateMethod"
typename="MyBusinessObject">
<updateparameters>
<asp:controlparameter name="anID" controlid="DropDownList1" propertyname="SelectedValue" />
</updateparameters>
</asp:objectdatasource>
Public Class MyBusinessObject
Public Shared Sub MyUpdateMethod(anID As String)
'data access code
End Sub
End Class
This pattern of putting control together can be quite productive, but you'll probably feel too restricted after a while.

NHibernate - Select query in Formula attribute of Property element is not working

I am new to NHibernate.
I am using following property elements in my hbm file...
<property name="CountryId" length="4" />
<property name="CountryForCustomer"
formula="(SELECT *
FROM SystemCountry
WHERE SystemCountry.CountryId = CountryId)" />
Here I am trying to get Country details from the CountryId that I am having in an other table.
Property "CountryForCustomer" is of custom type "SystemCountry".
But this query in formula is not working.. So someone please help me solving this issue.
Thanks in Advance....
Should it not be
SELECT SystemCountry.Country FROM SystemCountry WHERE...
as the * would return multiple columns from the query
edit If you want to return the whole object back then the property element is not your friend here. What you want to do is look at the many-to-one element, note that this is just one way to do this.
<many-to-one name="CmsTemplate" column="TemplateId" ..
e.g. here or here
the Formula mapping does not map its value from the database ,it maps its value from the dataset which is loaded in the session

ASP.NET : Passing a outside variable into a <asp:sqldatasource> tag ASP.NET 2.0

I'm designing some VB based ASP.NET 2.0, and I am trying to make more use of the various ASP tags that visual studio provides, rather than hand writing everything in the code-behind. I want to pass in an outside variable from the Session to identify who the user is for the query.
<asp:sqldatasource id="DataStores" runat="server" connectionstring="<%$ ConnectionStrings:MY_CONNECTION %>"
providername="<%$ ConnectionStrings:MY_CONNECTION.ProviderName %>"
selectcommand="SELECT THING1, THING2 FROM DATA_TABLE WHERE (THING2 IN (SELECT THING2 FROM RELATED_DATA_TABLE WHERE (USERNAME = #user)))"
onselecting="Data_Stores_Selecting">
<SelectParameters>
<asp:parameter name="user" defaultvalue ="" />
</SelectParameters>
</asp:sqldatasource>
And on my code behind I have:
Protected Sub Data_Stores_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles Data_Stores.Selecting
e.Command.Parameters("user").Value = Session("userid")
End Sub
Oracle squaks at me with ORA-01036, illegal variable name. Am I declaring the variable wrong in the query?
I thought external variables share the same name with a # prefixed. from what I understand, this should be placing the value I want into the query when it executes the select.
EDIT: Okay, thanks for the advice so far, first error was corrected, I need to use : and not # for the variable declaration in the query. Now it generates an ORA-01745 invalid host/bind variable name.
EDIT AGAIN: Okay, looks like user was a reserved word. It works now! Thanks for other points of view on this one. I hadn't thought of that approach.
I believe Oracle uses the colon ":", not the at-symbol "#".
"user" is probably a reserved word. Change it to "userID", or something similar.
You may want to consider using a SessionParameter instead of just a Parameter and let the SqlDataSource extract the user id directly from the session without any intervention on your part. Also, the example on the page linked above seems to imply that you should use ? instead of #user for parameter replacement for an ODBC connection. I think the parameter replacement would be done by the SqlDataSource and not passed to Oracle, that is it would substitute the actual value of the user id in place of the parameter (properly quoted of course) before sending the query to the database.
<SelectParameters>
<SessionParameter Name="userID" SessionField="user" DefaultValue="" />
</SelectParameters>
Using ASP.NET's SessionParameter is definitely the way to go here - that's why we have it :)
Using ASP.NET parameters you can easily include in your queries values from static sources, session state, query string, control property values, form post data, cookies, and user profile.
<asp:sqldatasource id="DataStores" runat="server" connectionstring="<%$ ConnectionStrings:MY_CONNECTION %>"
providername="<%$ ConnectionStrings:MY_CONNECTION.ProviderName %>"
selectcommand="SELECT THING1, THING2 FROM DATA_TABLE WHERE (THING2 IN (SELECT THING2 FROM RELATED_DATA_TABLE WHERE (USERNAME = #user)))"
onselecting="NAME_OF_SUB_Selecting">
<SelectParameters>
<asp:parameter name="#user1" defaultvalue ="" />
</SelectParameters>
</asp:sqldatasource>
Protected Sub NAME_OF_SUB_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles Data_Stores.Selecting
e.Command.Parameters("#user1").Value = Membership.GetUser.ProviderUserKey.ToString()
End Sub