.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Using LIKE with SelectParameter

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :ASP.Net

I'm trying to build a search feature where a user enters a text value and the page returns records where the string appears in a specific field. In short, its just not working. The SQL works find when I cut and paste into SQL Server Management Studio and replace the select parameter but it fails on the ASP.NET page.

Code behind

    Protected Sub Page_Load() Handles Me.Load

        Dim outerctl1 As Object = Master.FindControl("MyAccordion")
        Dim ctl As Object = outerctl1.FindControl("DashboardLinks")
        ctl.DashboardId = 1002

        test.Text = "[" & Request.QueryString("ShowNumber") & "]<br />"
        test.Text = test.Text & "[@SearchString Default] " & SqlDataSourceShowNotes.SelectParameters("SearchString").DefaultValue & "<br />"

        If Len(Request.QueryString("ShowNumber")) > 0 Then
            If Len(TextBoxShowNotesSearch.Text) > 0 Then
                SqlDataSourceShowNotes.SelectParameters("SearchString").DefaultValue = TextBoxShowNotesSearch.Text
                SqlDataSourceShowNotes.SelectParameters("SearchString").DefaultValue = ""
            End If
            SqlDataSourceShowNotes.SelectCommand = "SELEC

View Complete Post

More Related Resource Links

How do I change the SelectParameter to accept a datetime sql type?


Hi all, 

If I ran my sproc from query analyzer, I get the correct results(data is filtered by datetime), i.e:

 exec Uds.Dashboard_GetJobs '9/20/2010 11:01:23 PM'

However, if I ran it from the Asp.Net page, (ALL records are showed). Looking at the SQL Profiler I see the following call:
 exec sp_executesql N'exec Uds.Dashboard_GetJobs',N'@date nvarchar(21)',@date=N'9/20/2010 11:01:23 PM'

Running both statements above in the query analyzer it WILL return me different results. Why???

Someone mentioned that it looks like I don't have correct data type specified for SQLParameter in .Net application.
I was asked to create something like: cmd.Parameters.Add("@Date",SqlDbType.DateTime).Value = ..

Well, my code in the asp.net is in this form:

   <asp:SqlDataSource ID="sourceRealtimeLogging" runat="server"
      ConnectionString="<%$ ConnectionStrings:UctConnectionString %>"
      SelectCommand="exec Uds.Dashboard_GetJobs">
        <asp:ControlParameter ControlID="UpdatedTimeUTC" Name="date" PropertyName=&quo

Use data from First ObjectDataSource as SelectParameter for Second ObjectDataSource


I have defined an ObjectDataSource (sourceDocument) to retreive a record from database, the data is returned as a object from a class I programmed myself.

<asp:ObjectDataSource ID="sourceDocument" runat="server" 
                <asp:QueryStringParameter DefaultValue="0" Name="record_id" 
                    QueryStringField="DocID" Type="Int32" />

The object that is returend has a property called "SchoolDocument" which is a Boolean value

I am creating a second ObjectDataSource (sourceTypeList) that returns a DataSet of Doc Types.  I need to use the value of SchoolDocument from the first ObjecDataSource (sourceDocument) in the SelectParameter for the second ObjectDataSource (sourceTypeList).  This what I tired:

<asp:ObjectDataSource ID="sourceTypeList" runat="server" 
            OldValuesParameterFormatString="original_{0}" SelectMethod="GetList" 
                <asp:ControlParameter ControlID="sourceDocument" DefaultValue="false" 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend