我一直在重构旧的MSSQL Connection帮助程序库之一,但出现以下错误:
严重性代码说明项目文件行错误CS7036没有给出与'ErrorEventArg.ErrorEventArg(string,string)'所需的形式参数'errorMsg'相对应的参数,MSSQLTest C:\ Users \ Administrator \ Desktop \ MSSQLTest \ MSSQLTest \ MSSQLConnection。 CS 61
到目前为止,这是我的代码:
MSSQLConnection.cs
using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Threading; namespace MSSQLTest { public class ErrorEventArg : EventArgs { public string ErrorMsg { get; set; } public string LastQuery { get; set; } public ErrorEventArg(string errorMsg, string lastQuery) { ErrorMsg = errorMsg; LastQuery = lastQuery; } } public class MSSQLConnection { ////// Private class objects. /// private SqlConnection sqlConnection; private int sqlCommandTimeout; private string lastQuery = string.Empty; ////// Public event related objects & handler. /// public event ErrorHandler OnError; public delegate void ErrorHandler(MSSQLConnection sender, ErrorEventArg e); ////// Class constructor. /// /// /// public MSSQLConnection(SqlConnection sqlConnection, Int32 sqlCommandTimeout = 120) { if (null == sqlConnection) throw new Exception("Invalid MSSQL Database Conection Handle"); if (sqlConnection.State != System.Data.ConnectionState.Open) throw new Exception("MSSQL Database Connection Is Not Open"); this.sqlConnection = sqlConnection; this.sqlCommandTimeout = sqlCommandTimeout; } ////// Helper method to emit a database error to event subscribers. /// /// internal void EmitError(String errorMsg) { var errorDelegate = OnError; if (errorDelegate != null) { errorDelegate(this, new ErrorEventArg() // Line #61 { ErrorMsg = errorMsg, LastQuery = lastQuery }); } } /// rest of the code snipped } }
此错误是什么意思,我该如何解决?我之前没有看过这个错误...
您有一个带有2个参数的构造函数。您应该编写如下内容:
new ErrorEventArg(errorMsv, lastQuery)
它的代码更少,更易于阅读。
编辑
或者,为了工作,可以尝试为ErrorEventArg编写一个没有参数的默认构造函数,如下所示:
public ErrorEventArg() {}