错误提示如下:重载“Dispose”方法未获取“1”参数
我是按照书上做的,不知为什么有错误.
using System;
using System.Data.SqlClient;
using Common.Data;
using System.Data;namespace DA
{
/// <summary>
/// MrDep 的摘要说明。
/// </summary>
public class MrDep:IDisposable
{
private string conStr;
private SqlConnection con;
private SqlDataAdapter commandAdp; public MrDep()
{
//
// TODO: 在此处添加构造函数逻辑
//
conStr = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
con = new SqlConnection(conStr);
commandAdp = new SqlDataAdapter();
}
private string paramChg(string str)
{
str = "@"+str;
return str;
}
//添加机构信息
public bool InsertMrBranch(string branchName,string simpleCode)
{
SqlCommand command = new SqlCommand("InsertMrBranch",con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(paramChg(DepData.BRANCHNAME_FIELD),SqlDbType.VarChar);
command.Parameters.Add(paramChg(DepData.SIMPLECODE_FIELD),SqlDbType.VarChar);
command.Parameters[paramChg(DepData.BRANCHNAME_FIELD)].Value = branchName;
command.Parameters[paramChg(DepData.SIMPLECODE_FIELD)].Value = simpleCode; con.Open();
int result = command.ExecuteNonQuery();
if(result>0)
{
return true;
}
else
{
return false;
}
}
//更新机构信息
public bool UpdateMrBranch(int braID,string branchName,string simpleCode)
{
SqlCommand command = new SqlCommand("UpdateMrBranch",con);
command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int);
command.Parameters.Add(paramChg(DepData.BRANCHNAME_FIELD),SqlDbType.VarChar);
command.Parameters.Add(paramChg(DepData.SIMPLECODE_FIELD),SqlDbType.VarChar);
command.Parameters[paramChg(DepData.BRANCHID_FIELD)].Value = braID;
command.Parameters[paramChg(DepData.BRANCHNAME_FIELD)].Value = branchName;
command.Parameters[paramChg(DepData.SIMPLECODE_FIELD)].Value = simpleCode; con.Open();
int result = command.ExecuteNonQuery();
if(result > 0)
{
return true;
}
else
{
return false;
}
}
//删除机构信息
public bool DeleteMrBranch(int braID)
{
SqlCommand command = new SqlCommand("DeleteMrBranch",con);
command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int);
command.Parameters[paramChg(DepData.BRANCHID_FIELD)].Value = braID; con.Open();
int result = command.ExecuteNonQuery();
if(result > 0)
{
return true;
}
else
{
return false;
}
}
//读取所有机构信息
public DataSet GetBraData()
{
SqlCommand command = new SqlCommand("GetBraInf",con);
command.CommandType = CommandType.StoredProcedure; commandAdp.SelectCommand = command;
DataSet data = new DataSet();
commandAdp.Fill(data);
return data;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
}
}
我是按照书上做的,不知为什么有错误.
using System;
using System.Data.SqlClient;
using Common.Data;
using System.Data;namespace DA
{
/// <summary>
/// MrDep 的摘要说明。
/// </summary>
public class MrDep:IDisposable
{
private string conStr;
private SqlConnection con;
private SqlDataAdapter commandAdp; public MrDep()
{
//
// TODO: 在此处添加构造函数逻辑
//
conStr = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
con = new SqlConnection(conStr);
commandAdp = new SqlDataAdapter();
}
private string paramChg(string str)
{
str = "@"+str;
return str;
}
//添加机构信息
public bool InsertMrBranch(string branchName,string simpleCode)
{
SqlCommand command = new SqlCommand("InsertMrBranch",con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(paramChg(DepData.BRANCHNAME_FIELD),SqlDbType.VarChar);
command.Parameters.Add(paramChg(DepData.SIMPLECODE_FIELD),SqlDbType.VarChar);
command.Parameters[paramChg(DepData.BRANCHNAME_FIELD)].Value = branchName;
command.Parameters[paramChg(DepData.SIMPLECODE_FIELD)].Value = simpleCode; con.Open();
int result = command.ExecuteNonQuery();
if(result>0)
{
return true;
}
else
{
return false;
}
}
//更新机构信息
public bool UpdateMrBranch(int braID,string branchName,string simpleCode)
{
SqlCommand command = new SqlCommand("UpdateMrBranch",con);
command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int);
command.Parameters.Add(paramChg(DepData.BRANCHNAME_FIELD),SqlDbType.VarChar);
command.Parameters.Add(paramChg(DepData.SIMPLECODE_FIELD),SqlDbType.VarChar);
command.Parameters[paramChg(DepData.BRANCHID_FIELD)].Value = braID;
command.Parameters[paramChg(DepData.BRANCHNAME_FIELD)].Value = branchName;
command.Parameters[paramChg(DepData.SIMPLECODE_FIELD)].Value = simpleCode; con.Open();
int result = command.ExecuteNonQuery();
if(result > 0)
{
return true;
}
else
{
return false;
}
}
//删除机构信息
public bool DeleteMrBranch(int braID)
{
SqlCommand command = new SqlCommand("DeleteMrBranch",con);
command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int);
command.Parameters[paramChg(DepData.BRANCHID_FIELD)].Value = braID; con.Open();
int result = command.ExecuteNonQuery();
if(result > 0)
{
return true;
}
else
{
return false;
}
}
//读取所有机构信息
public DataSet GetBraData()
{
SqlCommand command = new SqlCommand("GetBraInf",con);
command.CommandType = CommandType.StoredProcedure; commandAdp.SelectCommand = command;
DataSet data = new DataSet();
commandAdp.Fill(data);
return data;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
}
}
好象 Dispose过程不需要参数?
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}再加一个重载函数试试
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}加上这个重载函数试一下~~
接口为的类,将强制调用dispose函数,而你的dispose里:
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
第一句代码是Dispose(true);而你的Dispose是没有参数的,所以出错
去掉它。
{
Dispose(true);
GC.SuppressFinalize(true);
}