60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Data.SqlClient;
|
|
using System.Data;
|
|
using System.Configuration;
|
|
|
|
/// <summary>
|
|
/// autoBindElab 的摘要描述
|
|
/// </summary>
|
|
public class autoBindElab
|
|
{
|
|
private string _strSQL = "";
|
|
private SqlConnection _objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ElabConnectionString"].ConnectionString);
|
|
private SqlCommand _objCmd;
|
|
private SqlDataAdapter _objDataAdapter;
|
|
private SqlCommandBuilder _objDataCommandBuilder;
|
|
private DataTable _objDataTable = new DataTable();
|
|
|
|
public autoBindElab(string strSQL)
|
|
{
|
|
//
|
|
// TODO: 在這裡新增建構函式邏輯
|
|
//
|
|
_strSQL = strSQL;
|
|
|
|
try
|
|
{
|
|
_objConn.Open();
|
|
_objCmd = new SqlCommand(_strSQL, _objConn);
|
|
_objDataAdapter = new SqlDataAdapter(_objCmd);
|
|
_objDataCommandBuilder = new SqlCommandBuilder(_objDataAdapter);
|
|
_objDataAdapter.Fill(_objDataTable);
|
|
_objConn.Close();
|
|
}
|
|
catch (Exception ex) {
|
|
throw new Exception("BindElab 發生錯誤! " + ex.Message);
|
|
}
|
|
}
|
|
|
|
public void updateDataTable() {
|
|
try
|
|
{
|
|
_objConn.Open();
|
|
_objDataAdapter.Update(_objDataTable);
|
|
_objConn.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_objConn.Close();
|
|
throw new Exception("ELab資料庫更新發生錯誤[" + _objDataTable.TableName + "], " + ex.Message);
|
|
}
|
|
}
|
|
|
|
public DataRowCollection dataRows {
|
|
get { return this._objDataTable.Rows; }
|
|
}
|
|
|
|
} |