本文主要是介绍通过配置DS操作数据库的常用代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
通过配置DS操作数据库的常用代码
查询代码:
public ShengDS GetIDSheng(int id)
{
ShengDS ds = new ShengDS();
this.sqlDataAdapter1.SelectCommand.CommandText="select * from sheng where ShengID="+id;
this.sqlDataAdapter1.Fill(ds);
return ds;
}
添加代码:
public int AddSheng(string sheng)
{
ShengDS ds = new ShengDS();
ShengDS.ShengRow dr = ds.Sheng.NewShengRow();
dr.ShengName=sheng;
dr.EndEdit();
ds.Sheng.Rows.Add(dr);
return this.sqlDataAdapter1.Update(ds);
}
删除代码:
public int DeleteSheng(int id)
{
ShengDS ds = new ShengDS();
this.sqlDataAdapter1.SelectCommand.CommandText="Select * from Sheng where ShengID="+id;
this.sqlDataAdapter1.Fill(ds);
if(ds.Sheng.Rows.Count==1)
{
ds.Sheng[0].Delete();
this.sqlDataAdapter1.Update(ds);
return 1;
}
else
{
return 0;
}
}
更新代码:
public int UpdateSheng(int shengid,string shengname)
{
ShengDS ds = new ShengDS();
this.sqlDataAdapter1.SelectCommand.CommandText="Select * from Sheng where ShengID="+shengid;
this.sqlDataAdapter1.Fill(ds);
if(ds.Sheng.Rows.Count==1)
{
ds.Sheng[0].ShengName=shengname;
this.sqlDataAdapter1.Update(ds);
return 1;
}
else
{
return -1;
}
}
这篇关于通过配置DS操作数据库的常用代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!