EndExecuteNonQuery 方法没有采用“0”个参数的重载
using System;
using System.Data;
using System.Data.SqlClient;
namespace ProDash
{
public class Data
{
private SqlConnection SqlConnection1;
private DataSql ds;
public Data()
{
SqlConnection conn = new SqlConnection("data source=.;uid=sa;pwd=sa;database=radb");
}
public int Insert(string tbId, string tbName, string cobYype, string cobTime)
{
ds=new DataSql();
int i = 0;
SqlCommand InsertCom = new SqlCommand();
try
{
InsertCom.CommandType = CommandType.Text;
ds.InsertData(InsertCom,tbId,tbName,cobYype,cobTime);
InsertCom.Connection = SqlConnection1;
SqlConnection1.Open();
i = Convert.ToInt32(InsertCom.EndExecuteNonQuery());
return i;
}
catch
{
throw;
}
finally
{
SqlConnection1.Close();
InsertCom.Dispose();
}
}
}
}
运行提示:错误 1 “EndExecuteNonQuery”方法没有采用“0”个参数的重载 C:\Documents and Settings\6515b\桌面\临时文件\ProDash\ProDash\Data.cs 31 36 ProDash
------解决方案--------------------C# code
i = Convert.ToInt32(InsertCom.ExecuteNonQuery());
------解决方案--------------------
用ExecuteNonQuery()...
------解决方案--------------------
public class Data
{
private slqConnection con;
private sqlCommand InsertCom;
private DataSql ds;
public Data()
{
}
private void Getcon()
{
conn = new SqlConnection("data source=.;uid=sa;pwd=sa;database=radb");
conn.open();
}
public int Insert(string tbId, string tbName, string cobYype, string cobTime)
{
this.Getcon();
ds=new DataSql();
int i = 0;
InsertCom = new SqlCommand();
try
{
InsertCom.CommandType = CommandType.Text;
ds.InsertData(InsertCom,tbId,tbName,cobYype,cobTime);
InsertCom.Connection = con;
i = InsertCom.ExecuteNonQuery();
return i;
}
catch
{
throw;
}
finally
{
InsertCom.Dispose();
con.Close();
}
}
}
呵呵,跟你把代码改动了一下,程序中有两个Sqlconnection对象,,,而命令行的对象指定的连接对象是SqlConnection1,而不是conn,释放资源是就出错了,还望指教