using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;


namespace CSharpdbService
{
	/// <summary>
	/// dbService的描述说明.
	/// </summary>
	public class dbService : System.Web.Services.WebService
	{
		public dbService()
		{
			//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
			InitializeComponent();
			connStr = "Provider=SQLOLEDB; Data Source=(local); ";
			connStr = connStr+" Initial Catalog=PUBS;User ID=sa;Password=";
		}
		private String connStr;
		
		

		#region Component Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容
		/// </summary>
		private void InitializeComponent()
		{
		}
		#endregion

		/// <summary>
		/// 清理要使用的资源.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
		}
		[WebMethod]
		public DataSet Populate(string SQL)
		{
			
			//用来返回查询的结果和与控件绑定
			OleDbConnection myConnection = new OleDbConnection(connStr);
			OleDbDataAdapter myCommand = new OleDbDataAdapter(SQL, myConnection);
			DataSet ds = new DataSet();
			myCommand.Fill(ds, "vTable");
			return ds;
		}
		[WebMethod]
		public String RunSQL( string vsql)
		{
			try
			{
				OleDbConnection myConnection = new OleDbConnection(connStr);
				OleDbCommand mycommand = new OleDbCommand(vsql,	myConnection);
				myConnection.Open();
				mycommand.ExecuteNonQuery();
				myConnection.Close();
				return("OK");
			}
			catch(Exception e)
			{
				string ret =	"Exception: " + e.ToString() ;
				return ret;
			}

			

		}
				
	}
}
