Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:09:58+00:00 2026-05-31T06:09:58+00:00

I am following this tutorial to create dynamic search results from an SQL server

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:09:59+00:00Added an answer on May 31, 2026 at 6:09 am

    Your web methods must be declared inside a class, and the attributes must decorate that class.

    [System.Web.Script.Services.ScriptService]
    [System.Web.Script.Services.GenerateScriptType(typeof(searchResult))]
    public class SearchService : WebService
    {
      [WebMethod]
      public searchResult[] Search(string txtSearch)
      {
         // ...
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following this tutorial to create dynamic search results from an SQL server
I've been experimenting with ASP.NET MVC and following this tutorial to create the basic
I was following this tutorial . I need to use a php file's ouput
I am following this tutorial and I've run the command ruby script\server and successfully
I'm new to NHibernate... I have been following this NHibernate Tutorial from Gabriel Schenker
I managed to get authentication to work by following the tutorial from this page
I am following this tutorial: https://github.com/amatsuda/kaminari/wiki/How-To:-Create-Infinite-Scrolling-with-jQuery So far everything works great, but I am
I'm following this tutorial here http://www.kriesi.at/archives/create-a-multilevel-dropdown-menu-with-css-and-improve-it-via-jquery on adding a menu with jquery. I've created
Hi. I have create a background service application following this tutorial http://androidsourcecode.blogspot.com/2010/10/basic-android-background-service.html . But
I'm following this tutorial: http://railscasts.com/episodes/253-carrierwave-file-uploads or atleast I want to but would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.