本次兩個的兩個數據是SQL Server 和ORCALsql
首先在Web.congfig中 數據庫
<connectionStrings> </connectionStrings>裏面添加兩個數據鏈接ide
在數據庫操做類中 寫兩個構造函數(一個是無參和有參的構造函數) 具體代碼以下函數
DataAccess() {
this.ConnectionSettings = ConfigurationManager.ConnectionStrings["FtpFileDownload"];
//this.ConnectionSettings = StaticValue.ConnectionSettings;
this.Factory = DbProviderFactories.GetFactory(this.ConnectionSettings.ProviderName);
}
public DataAccess(string ConnectionStringName)
{
this.ConnectionSettings = ConfigurationManager.ConnectionStrings[ConnectionStringName];
//this.ConnectionSettings = StaticValue.ConnectionSettings;
this.Factory = DbProviderFactories.GetFactory(this.ConnectionSettings.ProviderName);
}this
而後在調用就能夠了 具體代碼以下blog
string sql1 = "select top 1 * from tableNAme ORDER BY Id DESC";//直接查詢數據庫的第一一條數據
int prossed = DataAccess.Instance.ExecuteScalarGetInt(sql1);//直接查詢數據庫的最後一條數據
MessageBox.Show(prossed + " ");
string BL_NO = "OERT202202I00438";
DataAccess a= new DataAccess("SHA");
string selectSQL = "SELECT COUNT(id) FROM tableNAme WHERE BL_NO = '" + id+ "'";
int prosessed = a.ExecuteScalarGetInt(selectSQL);
MessageBox.Show(prosessed + " ");string