本文整理汇总了C#中MySql.Data.MySqlClient.MySqlDataReader.GetSchemaTable方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlDataReader.GetSchemaTable方法的具体用法?C# MySqlDataReader.GetSchemaTable怎么用?C# MySqlDataReader.GetSchemaTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlDataReader
的用法示例。
在下文中一共展示了MySqlDataReader.GetSchemaTable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: B_BDD_SQL_execute_Click
private void B_BDD_SQL_execute_Click(object sender, EventArgs e)
{
//nettoit completement la DGV
clear_SQL_DGV(DGV_GestionBDD_SQL_resultat);
//remplie la DGV
string requete = (string)CB_BDD_SQL_command.SelectedItem + " " + TB_BDD_SQL_column.Text + " " + L_BDD_SQL_from.Text + " " + (string)CB_BDD_SQL_table.SelectedItem + " " + L_GestionBDD_SQL_set_values.Text + " " + TB_GestionBDD_SQL_set_values.Text;
if (TB_BDD_SQL_condition.Text != "")
{
requete += " " + L_BDD_SQL_where.Text + " " + TB_BDD_SQL_condition.Text;
}
requete = requete.Split(';')[0];
try
{
switch ((string)CB_BDD_SQL_command.SelectedItem)
{
case "SELECT": Variable_Compte.Connection.Open();
Lecture = new MySqlCommand(requete, Variable_Compte.Connection);
Resultat = Lecture.ExecuteReader();
DataTable schemaTable = Resultat.GetSchemaTable();
for (int C = 0; C < schemaTable.Rows.Count; C++)
{
int emplacement = DGV_GestionBDD_SQL_resultat.Columns.Add(C.ToString(), schemaTable.Rows[C].ItemArray[0].ToString());
DGV_GestionBDD_SQL_resultat.Columns[emplacement].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
}
string[] row = new string[DGV_GestionBDD_SQL_resultat.Columns.Count];
while (Resultat.Read())
{
for (int i = 0; i < DGV_GestionBDD_SQL_resultat.Columns.Count; i++)
{
row[i] = Resultat[DGV_GestionBDD_SQL_resultat.Columns[i].HeaderText].ToString();
}
DGV_GestionBDD_SQL_resultat.Rows.Add(row);
}
Variable_Compte.Connection.Close();
label_NB_Ligne_Requete.Visible = true;
label_NB_Ligne_Requete.Text = DGV_GestionBDD_SQL_resultat.RowCount.ToString() + " lignes trouvées";
break;
case "UPDATE": Variable_Compte.Connection.Open();
Lecture = new MySqlCommand(requete, Variable_Compte.Connection);
Resultat = Lecture.ExecuteReader();
Variable_Compte.Connection.Close();
label_NB_Ligne_Requete.Visible = false;
MessageBox.Show("Base de données mise à jour.", "Opération efectuée");
break;
case "DELETE": Variable_Compte.Connection.Open();
Lecture = new MySqlCommand(requete, Variable_Compte.Connection);
Resultat = Lecture.ExecuteReader();
Variable_Compte.Connection.Close();
label_NB_Ligne_Requete.Visible = false;
MessageBox.Show("Base de données mise à jour.", "Opération efectuée");
break;
case "INSERT": Variable_Compte.Connection.Open();
ecriture = new MySqlCommand(requete, Variable_Compte.Connection);
ecriture.ExecuteNonQuery();
Variable_Compte.Connection.Close();
label_NB_Ligne_Requete.Visible = false;
MessageBox.Show("Base de données mise à jour.", "Opération efectuée");
break;
default: MessageBox.Show("Veuillez selectionner un ordre à exécuter sur la base de données.", "Opération annulée");
break;
}
}
catch (Exception ex)
{
MessageBox.Show("Une erreur s'est produite, veuillez vérifier votre requête SQL." + Environment.NewLine + ex.Message, "Opération annulée");
Variable_Compte.Connection.Close();
}
// permet de resize la DGV en fonction du nombre de ligne
if (40 + (DGV_GestionBDD_SQL_resultat.RowCount) * 22 < 254)
{
DGV_GestionBDD_SQL_resultat.Height = 40 + (DGV_GestionBDD_SQL_resultat.RowCount) * 22;
}
else
{
DGV_GestionBDD_SQL_resultat.Height = 254;
}
DGV_GestionBDD_SQL_resultat.CurrentCell.Selected = false;
}
示例2: GetNewDataTable
/// <summary>
/// MySqlDataReader转换成DataTable
/// </summary>
/// <param name="dataReader"></param>
/// <returns></returns>
public static DataTable GetNewDataTable(MySqlDataReader dataReader)
{
DataTable datatable = new DataTable();
DataTable schemaTable = dataReader.GetSchemaTable();
//动态添加列
try
{
foreach (DataRow myRow in schemaTable.Rows)
{
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = myRow.GetType();
myDataColumn.ColumnName = myRow[0].ToString();
datatable.Columns.Add(myDataColumn);
}
//添加数据
while (dataReader.Read())
{
DataRow myDataRow = datatable.NewRow();
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
myDataRow[i] = dataReader[i].ToString();
}
datatable.Rows.Add(myDataRow);
myDataRow = null;
}
schemaTable = null;
dataReader.Close();
return datatable;
}
catch (Exception ex)
{
throw new Exception("转换出错出错!", ex);
}
}
示例3: _readerFill
/*
* fill _dbData from the specified MySqlDataReader position
* Fetch the schema for the current table if we don't already have it (we should have)
*/
private bool _readerFill(MySqlDataReader reader)
{
if (!(_dbSchemas.ContainsKey(this._dbTable))) {
_dbSchemas[this._dbTable] = reader.GetSchemaTable();
}
this._dbData.Clear ();
for (int i = 0; i < reader.FieldCount; i++) {
this._dbData.Add (reader.GetName (i), reader[reader.GetName (i)]);
}
return true;
}