J'ai une fonction de type de retour datatableLes contrôles ne sont pas héritées dans WinForms
public DataTable GetAllPrimaryKeyTables(string ConnectionString)
{
// Create the datatable
DataTable dtListOfPrimaryKeyTables = new DataTable("tableNames");
// Query to select primary key tables.
string selectPrimaryKeyTables = @"SELECT
TABLE_NAME
AS
TABLES
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE = 'PRIMARY KEY'
AND
TABLE_NAME <> 'dtProperties'
ORDER BY
TABLE_NAME";
// put your SqlConnection and SqlCommand into using blocks!
using(SqlConnection sConnection = new SqlConnection(ConnectionString))
using(SqlCommand sCommand = new SqlCommand(selectPrimaryKeyTables, sConnection))
{
try
{
// Create the dataadapter object
SqlDataAdapter sDataAdapter = new SqlDataAdapter(selectPrimaryKeyTables, sConnection);
// Fill the datatable - no need to open the connection, the SqlDataAdapter will do that all by itself
// (and also close it again after it is done)
sDataAdapter.Fill(dtListOfPrimaryKeyTables);
//using(StringWriter sw = new StringWriter())
//{
// dtListOfPrimaryKeyTables.WriteXml(sw);
// sw.WriteLine();
// result = sw.ToString();
//}
}
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);
}
}
// return the data table to the caller
return dtListOfPrimaryKeyTables;
}
Et je l'appelle comme ça ...
public class PrimaryKeyChecker : IMFDBAnalyserPlugin
{
public DataTable RunAnalysis(string ConnectionString)
{
return GetAllPrimaryKeyTables(ConnectionString);
}
Dans le IMFDBAnalyserPlugin j'ai
namespace MFDBAnalyser
{
public interface IMFDBAnalyserPlugin
{
DataTable RunAnalysis(string ConnectionString);
}
et sur le fond du projet principal j'ai
private void btnStartAnalysis_Click(object sender, EventArgs e)
{
SqlConnectionStringBuilder objConnectionString = new SqlConnectionStringBuilder();
objConnectionString.DataSource = txtHost.Text;
objConnectionString.UserID = txtUsername.Text;
objConnectionString.Password = txtPassword.Text;
string[] arrArgs = {objConnectionString.ConnectionString};
string assemblyName = "PrimaryKeyChecker.dll";
Assembly assembly = Assembly.LoadFrom(assemblyName);
Type local_type = assembly.GetType("PrimaryKeyChecker.PrimaryKeyChecker");
MethodInfo objMI = local_type.GetMethod("RunAnalysis");
ConstructorInfo ci = local_type.GetConstructor(Type.EmptyTypes);
object responder = ci.Invoke(null);
object response = objMI.Invoke(responder, arrArgs);
Mais quand je debug, l'objet de réponse est de retour que le datatable vide que je suis incapable de donner la source de données dans la première fonction, car il ne hérite pas de contrôle là ...
Espérer la question est en partie clair pour vous les gars .. Il devrait donner la liste de toutes les tables lors du débogage, mais il ne prend pas la grille de données dgResultView là pour lui donner une source de données ...
Je ne vois pas où l'héritage de contrôle est pertinent ici du tout. Si vous placez des points d'arrêt dans la méthode RunAnalysis et que vous effectuez un débogage, que se passe-t-il? –