⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clsdb.cs

📁 通过掌上电脑管理SQL2000 SP3版本的软件! 功能还不错! 用于windows mobile2003或者WM5以上。VS2005下编译通过。
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;

	public class CConnection
	{
		#region "Class description"
		//This class provides database service to the web methods
		#endregion

		//Global declaration
		SqlConnection cn = new SqlConnection();	//to maintain global connection
		SqlDataAdapter da;	//to maintain data adapter
		//Structure to hold connection details
		public struct LoginInfo
		{
			public string sServer;
			public string sLoginName;
			public string sPassword;
			public string sDatabase;
		}
		private LoginInfo oLoginInfo;		
		//End Declaration

		public CConnection()
		{
			//Constructor
		}

		public bool fnConnectStatus(LoginInfo oLogInf)
		{
			//Establish connection and send the status
			oLoginInfo = oLogInf;
			fnConnect();
			if (cn.State.ToString() == "Open")
			{
				DisConnect();
				return true;
			}
			else
			{
				return false;
			}
		}
		private void fnConnect()
		{
			//Connecting to the server
			if (cn.State.ToString() != "Open") //Check it is not Open
			{
				if (oLoginInfo.sDatabase.Trim() != "")
				{
					cn = new SqlConnection("data source=" + oLoginInfo.sServer + ";uid = " + oLoginInfo.sLoginName + ";password = " + oLoginInfo.sPassword + ";database = " + oLoginInfo.sDatabase);
				}
				else
				{
					cn = new SqlConnection("data source=" + oLoginInfo.sServer + ";uid = " + oLoginInfo.sLoginName + ";password = " + oLoginInfo.sPassword + ";");
				}
				cn.Open();
			}
		}
		
		private void DisConnect()
		{
			//Disconnects the connection with the server
			if (cn.State.ToString() == "Open") //Check is it Open
			{
				cn.Close();
			}
		}

		public SqlDataAdapter ReturnAdapter(string sSql)
		{
			//Execute the query and return results as DataAdapter
			if (cn.State.ToString() != "Open") //Check it is not Open
			{
				fnConnect();
			}
			da = new SqlDataAdapter(sSql,cn);
			DisConnect();
			return da;
		}

		public DataSet ReturnDataset(string sSql)
		{
			//Execute the query and return results as DataSet
			DataSet ds = new DataSet();
			if (cn.State.ToString() != "Open") //Check it is not Open
			{
				fnConnect();
			}
			da = new SqlDataAdapter(sSql,cn);
			da.Fill(ds);
			DisConnect();
			return ds;
		}
		public SqlCommand ReturnCommand(string sSql)
		{
			if (cn.State.ToString() != "Open") //Check it is not Open
			{
				fnConnect();
			}
			SqlCommand dbCMD = new SqlCommand(sSql, cn);
			DisConnect();
			return dbCMD;
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -