自动完成扩展程序错误Asp.net [英] Auto complete extender error Asp.net

查看:67
本文介绍了自动完成扩展程序错误Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,开发人员.我想问一下一些调整.因此,即时通讯为我的项目使用了自动完成扩展程序,但根据选择的标准却出现了错误(基本上我想在哪里")
这就是我的项目背景:
我有一个下拉列表,其中的文本是字符串,值是整数
现在在我的自动完成扩展器上,我想要2个地方
这是我的试用代码

Hello fellow developer. Got a few tweakings I like to ask. So im using auto complete extender for my project, but getting an error based on selected criteria (basically I want to ''Where'')
So here is the background of my project:
I have a dropdown list where the text is string and the value is integer
now on my auto complete extender I want 2 where
here is my trial code

<WebMethod()> _
   Public Function Discipline() As String()

        Dim sqlConn As New SqlConnection(_connString)
        Dim count As Integer = 10
        Dim prefixText As String = Nothing
        Dim DisciplineID As Integer = Nothing
        Dim sql As String = "Select Distinct CourseName, CourseCode from Course Where DisciplineID=@DisciplineID And ([CourseCode] like @prefixText or [CourseName] like @prefixText)"
        Dim da As New SqlDataAdapter(sql, sqlConn)
        da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = "%" + prefixText + "%"
        da.SelectCommand.Parameters.Add("@DisciplineID", SqlDbType.VarChar, 50).Value = DisciplineID.ToString
        Dim dt As New DataTable()

        da.Fill(dt)

        Dim items As String() = New String(dt.Rows.Count - 1) {}
        Dim i As Integer = 0
        For Each dr As DataRow In dt.Rows
            items.SetValue(dr("CourseCode").ToString() & " | " & dr("CourseName").ToString(), i)

            i += 1
        Next
        Return items

    End Function


使用断点,我发现我的错误是在
将prefixText设为字符串=什么都没有
Dim DisciplineID为整数=没什么

因为它对参数没有任何说明.

我的问题是我可以在自动完成扩展程序上使用两个where原因吗,其中主子句将基于dropdownlist.selectedvalue ??

谢谢,还有更多功能.


Using break points I see that my error is on this on
Dim prefixText As String = Nothing
Dim DisciplineID As Integer = Nothing

Cause it says on the parameters nothing.

My question is can I use two where cause on an autocomplete extender where the primary clause will be based on dropdownlist.selectedvalue??

Thanks and more power.

推荐答案



如果您的数据行(dr)的内容为空,则可能必须创建一个函数以返回读取数据行(dr)的空字符串.

尝试将您的循环代码更改为以下示例:
Hi,

You have may have to create a function to return reading of your data row (dr) an empty string in case your data row (dr) contents null.

Try to change your code for loop as sample below:
For Each dr As DataRow In dt.Rows
   Items.SetValue(EmptyIfNull(dr("CourseCode")) & " | " & EmptyIfNull(dr("CourseName")), i)
   i += 1
Next



这是函数:



and here is the function:

Public Shared Function EmptyIfNull(ByVal p As Object) As String
       Dim retValue As String = String.Empty
       Try
           If Not (p.Equals(DBNull.Value)) Then
               'retValue = DirectCast(p, String)
               retValue = CType(p, String)
           End If
       Catch ex As Exception
           retValue = String.Empty
       End Try
       Return retValue
End Function




您也可以使用以下查询作为示例:(这是推荐的解决方案...)




You may also use such query as example: ( This is the recomended solution...)

Select Distinct case when CourseName = null  then '' else CourseName end, 
 case when CourseCode = null then '' else CourseCode end from Course 
Where DisciplineID=@DisciplineID And ([CourseCode] like @prefixText or [CourseName] like @prefixText)



希望这可以帮助...

问候



Hope this could help...

Regards,


这篇关于自动完成扩展程序错误Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆