In my Project, There are one or many Address_code are assigned to the particular Customer_Name. I have a one textbox Which hold Customer_Name. When I select particular Customer_Name which is populated using AutoCompleteExtender. Then I want to display Address_code related to that Customer_Name in the next Textbox.
Here is the code for select Customer, Which Works fine..
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> SearchCustomers(string prefixText, int count)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = dbConnection.fnConnectionString();
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = " SELECT CustomerCode,CustomerName FROM tblCustomer where " +
"CustomerName like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> customers = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
String Code = sdr["CustomerCode"].ToString();
String Name = sdr["CustomerName"].ToString();
Name = Name + " ("+Code + ")";
customers.Add(Name);
}
}
conn.Close();
return customers;
}
}
}
Here is code to display Addresscode in the another Textbox..Which is not working..
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> SearchAddress(string prefixText, int count)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = dbConnection.fnConnectionString();
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Addresscode from BName_Addresscode where Addresscode like '" + prefixText + "%' ";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> customers1 = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
// String Code = sdr["City"].ToString();
String Name = sdr["Addresscode"].ToString();
// Name = Code + "(" + Name + ")";
customers1.Add(Name);
}
}
conn.Close();
return customers1;
}
}
}