You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.6 KiB
C#
91 lines
3.6 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Data.SqlClient;
|
|
using System.Text;
|
|
// ReSharper disable once CheckNamespace
|
|
namespace DSWeb.SoftMng.DBUtility
|
|
{
|
|
public class DbHelperMdfSQL
|
|
{
|
|
//本地MDB数据库连接
|
|
public static DataSet Query(string version,string path)
|
|
{
|
|
try
|
|
{
|
|
//创建一个 OleDbConnection对象
|
|
string strCon = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = "+ path + "\\update.mdb";
|
|
OleDbConnection myConn = new OleDbConnection(strCon);
|
|
|
|
//创建一个 DataSet对象
|
|
var myDataSet = new DataSet();
|
|
myConn.Open();
|
|
//获取sql语句
|
|
string strCom = " SELECT * FROM t_sql where [版本号]>" + version + "";
|
|
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
|
|
myCommand.Fill(myDataSet, "t_sql");
|
|
//获取视图语句
|
|
string strCom1 = " SELECT * FROM t_view_update where [顺序]>" + version + "";
|
|
myCommand = new OleDbDataAdapter(strCom1, myConn);
|
|
myCommand.Fill(myDataSet, "t_view_update");
|
|
|
|
myConn.Close();
|
|
return myDataSet;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new DataSet();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// DataReader To DataSet
|
|
/// </summary>
|
|
/// <param name="reader"></param>
|
|
/// <returns></returns>
|
|
public DataSet ConvertDataReaderToDataSet(SqlDataReader reader)
|
|
{
|
|
DataSet dataSet = new DataSet();
|
|
do
|
|
{
|
|
// Create new data table
|
|
DataTable schemaTable = reader.GetSchemaTable();
|
|
DataTable dataTable = new DataTable();
|
|
if (schemaTable != null)
|
|
{
|
|
// A query returning records was executed
|
|
for (int i = 0; i < schemaTable.Rows.Count; i++)
|
|
{
|
|
DataRow dataRow = schemaTable.Rows[i];
|
|
// Create a column name that is unique in the data table
|
|
string columnName =
|
|
(string) dataRow["ColumnName"]; //+ " // Add the column definition to the data table
|
|
DataColumn column = new DataColumn(columnName, (Type) dataRow["DataType"]);
|
|
dataTable.Columns.Add(column);
|
|
}
|
|
dataSet.Tables.Add(dataTable);
|
|
// Fill the data table we just created
|
|
while (reader.Read())
|
|
{
|
|
DataRow dataRow = dataTable.NewRow();
|
|
for (int i = 0; i < reader.FieldCount; i++)
|
|
{
|
|
dataRow[i] = reader.GetValue(i);
|
|
}
|
|
dataTable.Rows.Add(dataRow);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// No records were returned
|
|
DataColumn column = new DataColumn("RowsAffected");
|
|
dataTable.Columns.Add(column);
|
|
dataSet.Tables.Add(dataTable);
|
|
DataRow dataRow = dataTable.NewRow();
|
|
dataRow[0] = reader.RecordsAffected;
|
|
dataTable.Rows.Add(dataRow);
|
|
}
|
|
} while (reader.NextResult());
|
|
return dataSet;
|
|
}
|
|
}
|
|
} |