{
//ConnectData connect = new ConnectData();
connect.Close_con();
connect.open_Con();
MySqlConnection myConnect = connect.NewConnection;
MySqlCommand cmdMySQL = myConnect.CreateCommand();
cmdMySQL.CommandText = commandString;
//connect.Close_con();
return cmdMySQL;
}
public DataTable ConvertDataReaderToDataTable(MySqlDataReader reader)
{
DataTable objDataTable = new DataTable();
int intFieldCount = reader.FieldCount;
int intCounter;
for (intCounter = 0; intCounter <= intFieldCount - 1; intCounter++)
objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter));
objDataTable.BeginLoadData();
Object[] objValues = new object[intFieldCount];
while (reader.Read())
{
reader.GetValues(objValues);
objDataTable.LoadDataRow(objValues, true);
}
reader.Close();
objDataTable.EndLoadData();
connect.Close_con();
return objDataTable;
}
public DataSet ConvertDataReaderToDataSet(MySqlDataReader 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());
connect.Close_con();
return dataSet;
}