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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:01:36+00:00 2026-05-27T08:01:36+00:00

I am trying to build a web service in .NET, which will retrieve data

  • 0

I am trying to build a web service in .NET, which will retrieve data from a mySQL database. This web service will later on be combined with a windows form where this data will be displayed.

Till now, I have the database ready, the connection between the database and the web service has been made and the form is ready as well.

However, I am unable to retrieve particular bits of information from the table itself. Can anyone help me to figure out what my next steps should be? I have googled a lot on this issue but I was still unable to find a good tutorial regarding this issue…if you have any in mind then can you please post the link as well? Thanks in advance!

EXTRA INFORMATION: Suppose a sample table called “testdata” which has three columns in it (“id”, “name”, “age”). How can I extract the name and the age and display them on the form?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace WebService2
{

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {



        private void connectoToMySql()
        {

            string connString = "SERVER=localhost" + ";" +
                "DATABASE=testdatabase;" +
                "UID=root;" +
                "PASSWORD=password;";

            MySqlConnection cnMySQL = new MySqlConnection(connString);

            MySqlCommand cmdMySQL = cnMySQL.CreateCommand();

            MySqlDataReader reader;

            cmdMySQL.CommandText = "select * from testdata";

            cnMySQL.Open();

            reader = cmdMySQL.ExecuteReader();


           //-----------------------------------------------------------
           // This is the part where I should be able to retrieve the data from the database
           //-----------------------------------------------------------               


            cnMySQL.Close();
        }


    }
}
  • 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-27T08:01:37+00:00Added an answer on May 27, 2026 at 8:01 am

    Create a method that is public, marked with the WebMethodAttribute, and returns a DataTable (if you consumer is a .net client). Have the consumer call that method and do whatever you want with the DataTable.

    [System.Web.Services.WebMethod]
    public DataTable connectoToMySql()
    {
        string connString = "SERVER=localhost" + ";" +
            "DATABASE=testdatabase;" +
            "UID=root;" +
            "PASSWORD=password;";
    
        MySqlConnection cnMySQL = new MySqlConnection(connString);
    
        MySqlCommand cmdMySQL = cnMySQL.CreateCommand();
    
        MySqlDataReader reader;
    
        cmdMySQL.CommandText = "select * from testdata";
    
        cnMySQL.Open();
    
        reader = cmdMySQL.ExecuteReader();
    
        DataTable dt = new DataTable();
        dt.Load(reader);
    
    
        cnMySQL.Close();
    
        return dt;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use a web service built on asp.net wcf from iPhone
I am trying to consume the webservice from the .Net environment which was build
I'm trying to build a web service using Ruby on Rails. Users authenticate themselves
I'm trying to build a generic web service interface using WCF, to allow 3rd
I'm trying to build the proxy class for a web service using the wsdl
I am trying to build an iPhone web application using ASP.NET. The page is
I'm trying to build a visual web part for SharePoint 2010 which should connect
I am trying to call some web services written in Java from my asp.net
I am trying to hit the following web service with axis2: http://www.webservicex.net/geoipservice.asmx?WSDL I have
I have a web service built for SharePoint 2007 that I am trying 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.