my source code is
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
$(document).ready(function()
{
SearchText();
});
function SearchText()
{
$(".autosuggest").autocomplete
(
{
source: function(request, response)
{
$.ajax
(
{
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/GetAutoCompleteData",
data: "{'username':'" + document.getElementById('TextBox1').value + "'}",
dataType: "json",
success: function(data)
{
response(data.d);
},
error: function(result)
{
alert("Type More Alphabet To search...");
}
});
}
});
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.Web.Services;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
string s = ConfigurationManager.AppSettings["s"].ToString();
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static List GetAutoCompleteData(string username)
{
List result = new List();
//using (SqlConnection con = new SqlConnection("data source=softech; initial catalog=emart; user id=sa; password=soft"))
using (SqlConnection con = new SqlConnection("data source=SELVI-PC\\SQLEXPRESS; Initial Catalog=bramandam;Integrated Security=True;"))
{
using (SqlCommand cmd = new SqlCommand("select DISTINCT Section from EmpReg where Section LIKE @SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", username);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["Section"].ToString());
}
return result;
}
}
}
}
My error isServer Error in '/Ajax' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL: |
Stack Trace:
|
Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971

Lakshmanan Sethu SankaranarayanPosted May 10, 2014, 6:40 AM
selvi subramanianPosted May 10, 2014, 6:27 AM