J'ai créé une méthode qui lierait toutes les tables avec des clés primaires dans un menu déroulant comme celui-ciméthode ne fonctionne pas correctement
public void PrimaryKeyTable()
{
SqlConnection sConnection = new SqlConnection("Server=192.168.10.3;DataBase=GoalPlanNew;User Id=gp;Password=gp");
//To Open the connection.
sConnection.Open();
string selectPrimaryKeys = @"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'PRIMARY KEY'
ORDER BY TABLE_NAME";
SqlCommand sCommand = new SqlCommand(selectPrimaryKeys, sConnection);
try
{
DataSet dsListOfPrimaryKeys = new DataSet("INFORMATION_SCHEMA.TABLE_CONSTRAINTS");
SqlDataAdapter dass = new SqlDataAdapter(selectPrimaryKeys, sConnection);
dass.TableMappings.Add("Table", "INFORMATION_SCHEMA.TABLE_CONSTRAINTS");
dass.Fill(dsListOfPrimaryKeys);
DataViewManager dsvaa = dsListOfPrimaryKeys.DefaultViewManager;
cmbResults.DataSource = dsListOfPrimaryKeys.Tables["INFORMATION_SCHEMA.TABLE_CONSTRAINTS"];
cmbResults.DisplayMember = "NAME";
cmbResults.ValueMember = ("");
}
catch (Exception ex)
{
//All the exceptions are handled and written in the EventLog.
EventLog log = new EventLog("Application");
log.Source = "MFDBAnalyser";
log.WriteEntry(ex.Message);
}
finally
{
if (sConnection.State != ConnectionState.Closed)
{
sConnection.Close();
}
}
}
mais au lieu de lier les tables avec des clés primaires, il donne quelque chose comme ça dans la liste déroulante
System.Data.DataRowView
System.Data.DataRowView...and so on
Pouvez-vous indiquer où je me suis trompé?
êtes-vous sûr de cette ligne 'cmbResults.DisplayMember =" Nom ";' nom de colonne est '" NAME "' – FosterZ