Hi
I hope u can help me...
i have a code that connect to mysql db and it works fine.
using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
namespace MySqlExample
{
class Program
{
static void Main(string[] args)
{
string host = "localhost";
string database = "articles";
string user = "root";
string password = "08031976";
string strSQL = "SELECT * FROM users";
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();
}
}
}
now i am trying to make this code into web service but without a succsess.
I keep getting this error :
Error 1 'WebService3.Service1.Main(string[])': not all code paths return a value.
this is the problematic 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";
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();
}
}
}
Please Help ...