UserControl与表单设计器相关的问题,因为我从C类调用方法#

问题描述 投票:0回答:1

1-我在app.config中添加了一个SQLite连接字符串,当我调用它时,表单设计器中出现错误(对象引用未设置为对象的实例)Designer error image

2-我试图通过索引号获取连接字符串,设计器中出现不同的错误(无法加载DLL'SQLite.Interop.dll':找不到指定的模块。(HRESULT异常:0x8007007E))Designer error image

App.config中:

<connectionStrings>
    <add 
           name="Cons" 
           connectionString="Data Source=|DataDirectory|PT.db; Version=3;" 
           providerName="System.Data.Sqlite"
     />
</connectionStrings>

在课堂电话中:

public class SQL
    {
        private static SQLiteConnection con = new SQLiteConnection(ConfigurationManager.ConnectionStrings["Cons"].ConnectionString);

        public static void Open()
        {
            con.Open();
        }
    }

[更新]

当我在ControlTime class中调用SQL UserControl中的任何方法时,我发现此问题存在

public partial class ControlTime : UserControl
    {
        public ControlTime()
        {
            InitializeComponent();
            SQL.Open(); // if i remove this line the error disappears 
        }
    }

如果在表单设计器中出现任何错误,我该怎么做才能调用SQL Class

c# sqlite system.data.sqlite
1个回答
0
投票

试试这个Connectionstring:

<connectionStrings>
    <add name="Cons" 
    connectionString="data source=.\PT.sqlite"
    providerName="System.Data.SQLite"/> 
</connectionStrings> 
© www.soinside.com 2019 - 2024. All rights reserved.