Showing posts with label sqldatasource. Show all posts
Showing posts with label sqldatasource. Show all posts

Thursday, March 8, 2012

Assign session variable value to update parameter

Hi, I'm trying to update a sqlserver database through vb.net in an asp.net 2.0 project. I'm using a sqldatasource and am trying to code an update parameter with a session variable.

code snippet:

<UpdateParameters><asp:ParameterName="hrs_credited"/>

<asp:ParameterName="updater_id"DefaultValue="<%$ Session("User_ID")%>"Type="Int32"/>

<asp:ParameterName="activity_id"/>

<asp:ParameterName="attendee_id"/>

</UpdateParameters>

The error message that I receive is:

Error 2 Literal content ('<asp:Parameter Name="updater_id" DefaultValue="" Type="Int32"/>') is not allowed within a 'System.Web.UI.WebControls.ParameterCollection'. C:\Development\CME\dataentry\attendance.aspx 29

Does anyone have an idea how to assign the session var value to the parameter?

Thanks!

There is a special parameter called a SessionParameter that does exactly that. Refer to this page for more information:http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx

Sunday, February 19, 2012

ASP: SqlDataSource - Select Command

I am using <asp:SqlDataSourceIDand for the Select Command, the following, where the WHERE clause ... for an exact match (=) works correctly:

SelectCommand="SELECT [PatientID], [MedRecord] , [Accession], [FirstName], [LastName], [Address1] FROM [ClinicalPatient] WHERE (LastName = @.LastName) ORDER BY [LastName]DESC">

I would like to do a "LIKE" search where the LastName Parameter is matched using "LIKE". In this situation how would the syntax be written...

I tried:

LastName LIKE '%" & LastName & "%'"

But I get an error????Any suggestions, please...

Thanks !!

Hey,

LastName like @.LastName

And you need to embed a % in the passed in parameter value.

|||

Hi and Thanks for getting back to me... however Im not sure that I understand your response... would really appreciate an 'example' or instruction on how to do what you indicate...

Thanks Again !!

|||

How are you assigning the value to the drop down? Because whatever value it uses is sent directly to the data source control. You need to modify the value sent. There are a couple of ways to do this. You could modify the textbox value and manually call the select() for the data source, but that would leave the % value in the textbox. Better would be to not use the ControlParameter parameter object, but to use Parameter. Tap into the Selecting event, and do this:

this.SqlDS.SelectParameters["LastName"].DefaultValue = "%" + this.txtLastName.Text + "%";

|||I took your lead...and I coded the 'LastName' value from the form search page, like this...

LastNamePresent ="%" & LastName.Text &"%"
and on the result page extracted the value from the QueryString and used it like this...

SelectCommand="SELECT [PatientID], [MedRecord] , [Accession], [FirstName], [LastName], [Address1] FROM [ClinicalPatient] WHERE [LastName] LIKE @.LastName ORDER BY [FirstName]ASC"
And OILA!!!!!
IT WOOOOOOOOOOOOOOOOOORKED !!!!

THANKS !!!!Big Smile