This is a migrated thread and some comments may be shown as answers.

RadSearch Errors out

1 Answer 112 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 16 Jan 2014, 04:51 PM
I pretty much duplicated the web service and example from the telerik example site but my web serive always returns the following error and I am wondering If I am missing some code somewhere.

Error
Object reference not set to an instance of an object.

The other question I have is once it returns correctly how do I get at the value.

<tr>
                            <td>Personnel Name: </td>
                            <td><telerik:RadSearchBox ID="rdSearch" runat="server" EmptyMessage="Type Last Name First Name" WebServiceSettings-Path="~/AutoComplete.asmx" WebServiceSettings-Method="GetNames"
                                EnableAutoComplete="true" MinFilterLength="2" MaxResultCount="20" ShowSearchButton="false" OnSearch="RadSearchBox3_Search"></telerik:RadSearchBox></td>
                        </tr>
 
public SearchBoxItemData[] GetNames(SearchBoxContext context)
    {
        DataTable data = GetData(context.Text);
 
        List<SearchBoxItemData> result = new List<SearchBoxItemData>();
 
        for (int i = 0; i < data.Rows.Count; i++)
        {
            SearchBoxItemData itemData = new SearchBoxItemData();
            itemData.Text = data.Rows[i]["strFullname"].ToString();
            itemData.Value = data.Rows[i]["intPersonnelId"].ToString();
 
            result.Add(itemData);
        }
 
        return result.ToArray();
    }
 
    private static DataTable GetData(string filterString)
    {
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ProdConnection"].ConnectionString);
        SqlCommand command = new SqlCommand("SELECT intPersonnelId, strFullname FROM MnNgPersonnel.dbo.tblMNNatPersonnel WHERE strFullname LIKE ' + @filterString + '%' ORDER BY strFullname");
        command.Parameters.AddWithValue("@filterString", filterString);
        command.Connection = connection;
        SqlDataAdapter adapter = new SqlDataAdapter(command);
 
        DataTable data = new DataTable();
        adapter.Fill(data);
        return data;
    }
























1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 17 Jan 2014, 12:23 PM
Hello Kevin,

The error you encounter is a general one and could occur as a result of different reasons.
However, I have replicated such an error when the connection string declaration is missing in the web.config file.

I have prepared a runnable sample project for you to help you setup your project. It is attached to this message.
For this sample, the connection string declaration in the web.config is as follows:
<add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

You may need to add a similar line in your web.config. Note that you need to change the "Data Source=.\SQLEXPRESS" instance with the one of your SQL server instance, in order to run the sample. In your case, it may be something like "Kevin\SQLEXPRESS".

About your second question on how to get at the value, I am not sure if you need it on client-side or server-side. I am sending you a Client-side Programming article from the RadSearchBox Documentation. You can find Server-side Programming documentation there, as well.

In addition, I am sending you the Client-Side Events and the Server-side Events demos.

I hope that would solve your issues.

Regards,
Dimitar
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
SearchBox
Asked by
Kevin
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or