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

  • Home
  • SEARCH
  • 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 6788531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:29:49+00:00 2026-05-26T17:29:49+00:00

I have a Web Service(.ASMX) code that takes a String Array as a parameter

  • 0

I have a Web Service(.ASMX) code that takes a String Array as a parameter and then inserts each individual value in the database

For example let’s say I have array like:

            String arr[]={"john","annie"};

Now I want to put “john” and “annie” in a column in my database

I have implemented a code for it but it’s not working and the values are not inserted. Also is there any way to test my webservice application on localhost in my browser.

Here is the web service code:

      public class Service1 : System.Web.Services.WebService
     {
    [WebMethod]

    public String getnames(String[] values)
    {

        try
        {

            using (SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123"))
            {
                int count = 1;
                int rows = 0;

                myConnection.Open();
                foreach (string student in arr)
                {
                    count++;
                    using (SqlCommand myCommand = new SqlCommand())
                    {
                        myCommand.Connection = myConnection;
                        myCommand.CommandText = "insert into record values(@pCount, @pStudent)";
                        SqlParameter param = myCommand.CreateParameter();
                        param.ParameterName = "@pCount";
                        param.Value = count;
                        myCommand.Parameters.Add(param);

                        param = myCommand.CreateParameter();
                        param.ParameterName = "@pSudent";
                        param.Value = student;

                        rows = myCommand.ExecuteNonQuery();
                    }
                }
            }
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            return "an error occured";
        }


        return "success";
        }
     }
   }
  • 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-26T17:29:49+00:00Added an answer on May 26, 2026 at 5:29 pm

    YOu can debug your service by making the asmx the startpage and clicking run to debug. You should be able to fill in a value into the text box if you are accepting paramaters.

    I would do it different I would create a Stored proc to handle the work that looks like this The code assumes a delimited string so its not an array scenario.. but its awesome code..

    create Proc [dbo].[InsertINtoRecords] (@sep VARCHAR(32), @s VARCHAR(MAX))
    AS
    
        BEGIN
            Declare @t TABLE
            (
                val VARCHAR(MAX)
            )   
    
    
            DECLARE @xml XML
            SET @XML = N'<root><r>' + REPLACE(@s, @sep, '</r><r>') + '</r></root>'
    
            INSERT INTO @t(val)
            SELECT r.value('.','VARCHAR(100)') as Item
            FROM @xml.nodes('//root/r') AS RECORDS(r)
    
            insert into record(Count, Student) Select ROW_NUMBER() OVER (ORDER BY val) AS Count, Val
    
        END
    

    Then your code would only have to do this

                    Names = "Johny,Anne,sally"
                    myCommand.Connection = myConnection;
                    myCommand.CommandText = "InsertINtoRecords ',', @Names";
                    rows = myCommand.ExecuteNonQuery();
    

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is that Web Service files (.asmx) have their code-behind placed in app_code folder
I have a web service (ASMX) and in it, a web method that does
I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I have an asmx web service that should only be allowed to respond to
I have a web service that contains 2 asmx files (public.asmx and private.asmx). On
I have an application that is an asmx web service written in .NET 2.0
I have a asmx web-service that returns a list of countries for a continent.
I have implemented a web service(.asmx) using .NET framework that returns me a hash
I have a ASP.NET web service ( .asmx ) with methods that receives int
I have a web service (WCF or ASMX doesn't matter)... I have made a

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.