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

📄 accessdata.cs

📁 车载GPS?今天这个就是最好的工具
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.EnterpriseServices;
[Transaction(TransactionOption.Required),
JustInTimeActivation(true), 
ObjectPooling(Enabled=true, MinPoolSize=2, MaxPoolSize=10), 
ConstructionEnabledAttribute(Default="Server=localhost;DataBase=Northwind;user id=sa;password=sasa")]
public class AccessData
{
	public AccessData()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
	protected const string CONNECTION_ERROR_MSG  = "数据库连接失败! ";

	protected const string SQL_CONNECTION_STRING  = @"Data Source=gers;DataBase=gero;user id=sa;password=sasa";
                                                    
	protected const string MSDE_CONNECTION_STRING  = @"Server=zhaomg\pcms;DataBase=gero;user id=sa;password=pcms;Integrated Security=SSPI";
	private string Connectionstring  = MSDE_CONNECTION_STRING;
    private string ConnectString=MSDE_CONNECTION_STRING;

	private SqlDataAdapter drSQL;
	public delegate void ConnectionStatusChangeDelegate(string status);
	public event ConnectionStatusChangeDelegate ConnectionStatusChange;
    
	public delegate void ConnectionFailureDelegate(string status);
	public event ConnectionFailureDelegate ConnectionFailure;

	public delegate void ConnectionCompletedDelegate(string status);
	public event ConnectionCompletedDelegate ConnectionCompleted;

	protected string strConn  = MSDE_CONNECTION_STRING;

	public string  ConnectionString
	{
		get
		{
			return this.Connectionstring ;
		}

	}


	public void ExecuteSQL( string strSQL)
	{

		SqlConnection cnSQL;

		SqlCommand cmSQL;

		bool IsConnecting = true;

		while (IsConnecting)
		{
			try 
			{

				cnSQL = new SqlConnection(Connectionstring);

				cnSQL.Open();

				cmSQL = new SqlCommand(strSQL, cnSQL);

				cmSQL.ExecuteNonQuery();

				cnSQL.Close();

				cmSQL.Dispose();

				cnSQL.Dispose();
				IsConnecting = false;

			} 
			catch(SqlException Exp) 
			{
//				if (strConn == SQL_CONNECTION_STRING)
//				{
//                    
//					Connectionstring = MSDE_CONNECTION_STRING;
//
//				}
//				else 
//				{
                   IsConnecting = false;
					MessageBox.Show(CONNECTION_ERROR_MSG);

//				}

			} 
			catch(Exception Exp)
			{
				MessageBox.Show(Exp.Message, "General Error");
			}

		}
	}
	//execute select statment
	public DataTable SelectSQL(string strSQL)
	{
		DataTable GreatDataTable = new DataTable();
		bool IsConnecting = true;

		while (IsConnecting)
		{
			try
			{

				SqlConnection cnSQL = new SqlConnection(Connectionstring);
				cnSQL.Open();
				SqlCommand cmSQL = new SqlCommand(strSQL, cnSQL);
				drSQL = new SqlDataAdapter(cmSQL);
				SqlCommandBuilder scb =new SqlCommandBuilder (drSQL);
				
				this.drSQL.Fill(GreatDataTable);

				cnSQL.Close();

				cmSQL.Dispose();

				cnSQL.Dispose();

				IsConnecting = false;
				
			} 
			catch(SqlException e)
			{
//				if (strConn == SQL_CONNECTION_STRING)
//				{
//					Connectionstring = MSDE_CONNECTION_STRING;
//				}
//				else 
//				{
					MessageBox.Show(CONNECTION_ERROR_MSG);
//				}


			} 
			catch(Exception e)
			{
				MessageBox.Show(e.Message, "SQL Error");

			}
		}

		return GreatDataTable;
}
	public string GetMakeId(string TableName,string lsId)
		{
            DataTable dt=new DataTable();
			DataRow dr;
			string lsSQL="select max(" + lsId + ")  from "+ TableName;
            dt=SelectSQL(lsSQL);
			dr=dt.Rows[0];
			int i=Int32.Parse(dr[0].ToString())+1;
			return i.ToString();

		}
	
   

	}

⌨️ 快捷键说明

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