Created
July 29, 2017 21:14
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Web.Script.Services.ScriptMethod()] | |
[System.Web.Services.WebMethod] | |
public static List<string> SearchCustomer(string prefixText, int count) | |
{ | |
string conString = ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString"].ConnectionString; | |
using (SqlConnection conn = new SqlConnection(conString)) | |
{ | |
using (SqlCommand cmd = new SqlCommand()) | |
{ | |
cmd.CommandText = "SELECT FirstName FROM [AdventureWorks].[dbo].[DimCustomer] where FirstName like @Searchtext + '%'"; | |
cmd.Parameters.AddWithValue("@Searchtext", prefixText); | |
cmd.Connection = conn; | |
conn.Open(); | |
List<string> names = new List<string>(); | |
using (SqlDataReader sdr = cmd.ExecuteReader()) | |
{ | |
while (sdr.Read()) | |
{ | |
names.Add(sdr["FirstName"].ToString()); | |
} | |
} | |
conn.Close(); | |
return names; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment