Hi
i created a small program that does
connection to db and perform a select.
that's works fine for me.
now,i want to make it a web service,
but how can i return the result of the select query from it?
please help...
this is my code...
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
namespace WebService3
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string Main(string[] args)
{
string host = "localhost";
string database = "articles";
string user = "root";
string password = "08031976";
string strSQL = "SELECT * FROM users";
return "some string";
string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
try
{
MySqlConnection mysqlCon = new MySqlConnection(strProvider);
mysqlCon.Open();
if (mysqlCon.State.ToString() == "Open")
{
Console.WriteLine("Database Connection Open");
Console.WriteLine("------------------------");
MySqlCommand mysqlCmd = new MySqlCommand(strSQL, mysqlCon);
MySqlDataReader mysqlReader = mysqlCmd.ExecuteReader();
Console.WriteLine("Id\tName\tLastName");
Console.WriteLine("------------------------");
while (mysqlReader.Read())
{
Console.WriteLine(mysqlReader.GetInt32(0) + "\t" + mysqlReader.GetString(1) + "\t" + mysqlReader.GetString(2));
}
}
mysqlCon.Close();
}
catch (Exception er)
{
Console.WriteLine("An Error Occured" + er.Message);
}
Console.ReadKey();
}
}
}