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 6375735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:39:14+00:00 2026-05-25T01:39:14+00:00

I am finding it difficult to implement a .NET web service to insert data

  • 0

I am finding it difficult to implement a .NET web service to insert data in my database created in SQL Server 2008 . I am stuck after implementing the following code :

namespace DataService
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]

    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld(String entity)
        {
            String firstName = "";
            SqlConnection myConnection = new SqlConnection(
                @"Data Source=.\SQLEXPRESS;" + 
                @"Initial Catalog=student;User ID=sa;Password=123");
            try
            {
                myConnection.Open();
                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection = myConnection;
                myCommand.CommandText = "insert into stud values " +
                    "stud_name = '" + firstName + "'";

                SqlDataReader myReader = myCommand.ExecuteReader();

                //while
                if (myReader.Read())
                {
                    firstName = myReader["stud_name"].ToString();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            { 
                myConnection.Close();
            }

            return firstName;
        }
    }
}

Here entity is the JSONArray i get in the form:

[{"key0":"john","key2":"ann","key1":"joe"}]

I need to insert each value for eg “john” in the database table.

  • 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-25T01:39:14+00:00Added an answer on May 25, 2026 at 1:39 am

    Parth_90:

    First, if you are getting a JSONArray from the client side, I suggest you Deserialize it first in a List

    JavascripSerializer js = new JavascriptSerializer<List<sring>>();
    List<string> recordsToInsert= js.Deserialize(entity);
    

    Then you can insert every record in the table by either looping through them and enclosing everything in a Transaction.

    foreach(name in recordsToInsert)
    {
     //perform the table insert here... 
     //Your SQL code seems correct to me. 
    }
    

    Improvement: Enclose the insert statements in a SQLTransaction.

    EDIT: Adding some code demonstrating how to Deserialize the example JSON string provided in the question:

    private static void DoSerializationTest()
        {
            string entity="{\"key0\":\"john\",\"key2\":\"ann\",\"key1\":\"joe\"}";
            JavaScriptSerializer js = new JavaScriptSerializer();
    
            Dictionary<string,string> result= js.Deserialize<Dictionary<string,string>>(entity);
            foreach (var item in result)
            {
                Console.WriteLine("Value: "+item.Value);
                Console.WriteLine("Key :"+item.Key);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to view the transaction logs of a database on SQL Server 2008
I'm finding it difficult to find a decent example on how to implement a
I have a Hello World c# ASP .NET web service which is automatically generated
I am trying to implement an algorithm in SQL (transact sql) and finding it
I am finding it difficult to find anyway to implement Reflection in C++. I
In designing a data-entry form, I'm finding it difficult to get the second column,
Currently I am designing a website and I am finding it VERY difficult to
Finding windows FastCGI help is proving very difficult. Any help would be greatly apprciated.
I am new to prototype and finding it a lot more difficult than jquery.
All, Below is the lambda expression which I am finding difficult to reduce i.e.

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.