I am following this tutorial to create dynamic search results from an SQL server as a user types. It is telling me to create a .asmx file, which is not a format I have ever worked with before. Here is the code I have thus far :
WebService.asmx.cs :
public class SearchService : WebService
{
[WebMethod]
public searchResult[] Search(string txtSearch)
{
//Declare collection of searchResult
List resultList = new List();
var db = Database.Open("mPlan");
var result = db.Query("SELECT * from Users where Username like '%" + txtSearch + "%'");
try
{
foreach(var record in result)
{
searchResult result = new searchResult();
result.Username = ["Username"].ToString();
resultList.Add(result);
}
return resultList.ToArray();
}
catch
{
return null;
}
}}
WebService.asmx :
<%@ WebService Language="C#" class="WebService.asmx.cs" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
[System.Web.Script.Services.ScriptService]
[System.Web.Script.Services.GenerateScriptType(typeof(searchResult))]
public class searchResult
{
public string Title;
public string img;
public string href;
}
Here is my error message, can anyone help me with this please?
Compiler Error Message: BC30689: Statement cannot appear outside of a method body