我在写一个删除数据行的模块(用三层),但是不知道怎么进行下去了!
以下是我的语句,求高手帮我看看,是什么问题,该怎么解决:
System.Data.SqlClient.SqlDataAdapter myada;
SqlConnection mycon;
public DBO()
{
}
//用于获得连接
public SqlConnection getcon()
{
mycon=new SqlConnection("server=.;uid=sa;pwd=;database=scalemanage");
return mycon;
}
public void del(DataSet dataset,string tb)
{
// dataset.Tables[tb].Rows[j].Delete();
// this.mycon.Open
// SqlCommand com=new SqlCommand(sql,mycon);
// com.ExecuteNonQuery();
myada.Update(dataset,tb);
}
//以上是数据库层
System.Data.SqlClient.SqlDataAdapter myada;
AstraLink.DBO.DBO objdbo=new AstraLink.DBO.DBO();
DataSet dataset=new DataSet();
System.Data.SqlClient.SqlParameter myparam;
public void delprod(DataSet dataset,int j)
{
try
{
string sql;
sql="delete from product where plu=@aaa";
SqlConnection mycon=new SqlConnection();
mycon=objdbo.getcon();
this.myada=new SqlDataAdapter("select * from product",mycon);
this.myada.DeleteCommand=new SqlCommand(sql,mycon);
// SqlCommand cmd=new SqlCommand(sql,mycon);
// this.myada=new SqlDataAdapter("select * from product",mycon);
// this.myada.DeleteCommand=new SqlCommand(sql,mycon);
this.myparam=this.myada.DeleteCommand.Parameters.Add("@aaa",SqlDbType.Int);
this.myparam.SourceColumn="plu";
this.myparam.SourceVersion=DataRowVersion.Current;
this.dataset.Tables["product"].Rows[j].Delete();
// DataView dv=new DataView(dataset.Tables["product"]);
// this.myada.Update(dataset,"product");
objdbo.del(dataset,"product");
}
catch(Exception e)
{
throw(e);
}
}
//以上是中间层
AstraLink.Excute.ExcuteProduct ep;
DataSet dataset=new DataSet();
private void button3_Click(object sender, System.EventArgs e)
{
try
{
string s="";
s="delete from product where plu=@aaa";
System.Data.SqlClient.SqlConnection mycon=new SqlConnection("server=,;uid=sa;pwd=;database=product");
mycon.Open();
System.Data.SqlClient.SqlDataAdapter myada=new SqlDataAdapter("select * from product",mycon);
myada.DeleteCommand=new SqlCommand(s,mycon);
System.Data.SqlClient.SqlParameter myparam=new SqlParameter("@aaa",SqlDbType.Int);
myparam=myada.DeleteCommand.Parameters.Add("@aaa",SqlDbType.Int);
myparam.SourceColumn="plu";
myparam.SourceVersion=DataRowVersion.Current;
dataset.Tables[0].Rows[this.dataGrid1.CurrentRowIndex].Delete();
myada.Update(dataset,"product");
}
catch(Exception ex3)
{
MessageBox.Show(ex3.Message);
}
//以上是界面层!!!