Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 控件不会在winforms中继承_C#_Visual Studio_Winforms_Debugging_Datatable - Fatal编程技术网

C# 控件不会在winforms中继承

C# 控件不会在winforms中继承,c#,visual-studio,winforms,debugging,datatable,C#,Visual Studio,Winforms,Debugging,Datatable,我有一个返回类型datatable的函数 public DataTable GetAllPrimaryKeyTables(string ConnectionString) { // Create the datatable DataTable dtListOfPrimaryKeyTables = new DataTable("tableNames"); // Query to select primary key tables. string selectP

我有一个返回类型datatable的函数

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;
}
在我的IMFDBAnalyserPlugin里

namespace MFDBAnalyser
{
    public interface IMFDBAnalyserPlugin
    {
        DataTable RunAnalysis(string ConnectionString);
    }
关于我的主要项目背景

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);
但是当我调试时,响应对象只返回空datatable,因为我无法在第一个函数中提供数据源,因为它没有继承那里的控件


希望你们对这个问题有一部分的了解。。调试时,它应该给出所有表的列表,但它没有将datagrid dgResultView放在那里作为数据源…

这与继承无关;看起来您正在捕获并记录异常:

    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);
    }
我会先看看那里;最有可能的事情是扔东西,并告诉你为什么。。。如果让我猜的话,看起来你可能失踪了:

sConnection.Open();
返回的任何内容都告诉我这只是一个例外

就我个人而言,我会让一个意料之外的异常冒泡到UI上,让UI通过记录它并显示相应的#fail页面来做出反应

此外,如果可能,将插件强制转换到接口:

string assemblyName = "PrimaryKeyChecker.dll";
Assembly assembly = Assembly.LoadFrom(assemblyName);
Type local_type = assembly.GetType("PrimaryKeyChecker.PrimaryKeyChecker");
IMFDBAnalyserPlugin analyser =
   (IMFDBAnalyserPlugin)Activator.CreateInstance(local_type);
DataTable response = analyser.RunAnalysis(objConnectionString.ConnectionString);

我根本看不出控制继承在哪里是相关的。如果在RunAnalysis方法中设置断点并进行调试,会发生什么情况?但是。。DataTable响应没有给出函数GetAllPrimaryKeyTables()所使用的所有表的列表generating@Srivastava-没有;因为它正在抛出一个异常。在这个方法中放置一个断点并跟踪它。@Srivastava-它也可能像错误的密码一样愚蠢,但在检查您记录的异常之前,您不会知道inpupt字符串的格式不正确,而是它在事件查看器中引发的异常。
string assemblyName = "PrimaryKeyChecker.dll";
Assembly assembly = Assembly.LoadFrom(assemblyName);
Type local_type = assembly.GetType("PrimaryKeyChecker.PrimaryKeyChecker");
IMFDBAnalyserPlugin analyser =
   (IMFDBAnalyserPlugin)Activator.CreateInstance(local_type);
DataTable response = analyser.RunAnalysis(objConnectionString.ConnectionString);