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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:38:15+00:00 2026-06-04T18:38:15+00:00

I am new to webservice development. I have made webservice in asp.net using c#

  • 0

I am new to webservice development. I have made webservice in asp.net using c# and mysql.

I want to store values of select query in variable which then i want to insert in table.

I have used following code :

//for inserting new game details in the tbl_Game by FB
    [WebMethod]
    public string InsertNewGameDetailsForFB(string gametype, string player1, string player2, string player3, string player4, string player5)
    {
        string success = "Error in Insertion";

        string selectID = "Select UserID from tbl_userinfo where Facebook_ID IN ('" + player1 + "','" + player2 + "','" + player3 + "')";
        con = new MySqlConnection(conString);
        con.Open();
        MySqlCommand cmd = new MySqlCommand(selectID, con);
        MySqlDataReader ids = cmd.ExecuteReader();
        string id1="", id2="", id3="";
        while (ids.Read())
        {
           id1 = ids.GetString(0);
           id2 = ids.GetString(1);
           id3 = ids.GetString(2);

        }

        string insertNewGame = "Insert into tbl_game(Type,Player1,Player2,Player3,Player4,Player5) values";
        insertNewGame += "( '" + gametype + "' , '" + id1 + "', '" + id2 + "','" + id3 + "', '" + player3 + "','" + player4 + "', '" + player5 + "' )";
        con = new MySqlConnection(conString);
        con.Open();
        MySqlCommand cmd1 = new MySqlCommand(insertNewGame, con);
        int success1 = cmd1.ExecuteNonQuery();
        con.Close();

        string gameID = "Select MAX(GameID) from tbl_game";
        con = new MySqlConnection(conString);
        con.Open();
        MySqlCommand cmd2 = new MySqlCommand(gameID, con);
        string gameid = cmd2.ExecuteScalar().ToString();

        if (success1 > 0)
        {
           success="Inserted Successfully, GameID is - " + gameid;
        }
        return success;
    }

how can i do this ?

Thanks.

  • 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-06-04T18:38:17+00:00Added an answer on June 4, 2026 at 6:38 pm

    Your first issue is how you’re attempting to read in UserID from your first query. This query will not return three columns but three rows. So you need to do something like this:

    int index = 0;
    while (ids.Read())
    {
        switch (index)
        {
            case 0:
                id1 = ids.GetString(0);
                break;
            case 1:
                id2 = ids.GetString(0);
                break;
            case 2:
                id3 = ids.GetString(0);
                break;
        }
        index += 1;
    }
    

    That should store them properly. My second suggestion is since this is a web service, you should avoid SQL Injection attacks and use parameterized queries rather than dynamic SQL. There are plenty of examples on the web you can use.

    My final suggestion is to use the using statement religiously for objects which implement IDisposable (i.e. the connection object, the command, the reader, etc…). This ensures proper cleanup of objects.

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

Sidebar

Related Questions

I have created a new VS2008 ASP.Net Web service project, with the default name
I'm new to webservice development. I'm using Netbeans 7.0 with the Axis2 plugin and
I'm new to webservice development. I'm using Netbeans 7.0 with the Axis2 plugin and
I have a simple class in an ASP.NET webservice. It runs fine on my
I have a newbie question. If in my asp.net application I need to query
I'm fairly new to WebService developement and have just set up my own webservice
i am new in blackberry development. and i have task to develop the application
I'm working on a web site where the new pages are ASP.NET and the
I'm completely new to Amazon AWS development and the Product Advertising API. I have
I have created a webservice and I want to use a android phone as

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.