期望参数@id不被提供 [英] expect parameter @id which was not suppled

查看:91
本文介绍了期望参数@id不被提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai all,

当我为我的数据主义者开发无限滚动时我正在寻找小问题可以任何人帮助我



if(Session [id]!= null)

{

mydb db = new mydb();

/ /最初获取14条记录。

DataSet dsProducts = db.GetProducts();

//将数据绑定到gridview

dl.DataSource = dsProducts ;

dl.DataBind();

}



}

protected void btnGetMoreRecords_Click(object sender,EventArgs e)

{

mydb db = new mydb();

//最初获取14条记录。

DataSet dsProducts = db.FetchNextProducts(Convert.ToInt32(hiddenLastProductID.Value),14);

//将数据绑定到gridview

dl。 DataSour ce = dsProducts;

dl.DataBind();



错误:期望参数@id不被提供





}



公共舱mydb

{

private SqlConnection con;

public mydb()

{

con = new SqlConnection(ConfigurationManager.ConnectionStrings [conn ] .ConnectionString);

}



公共DataSet GetProducts()



{



SqlCommand cmd = new SqlCommand(tb_userdata.uidfromtb1 = tb_userlogin.id,tb_userlogin.id = @,从tb_userdata内部联接tb_userlogin中选择前5名decription,url id,con);

cmd.Parameters.AddWithValue(@ id,id);



SqlDataAdapter da = new SqlDataAdapter(厘米d);

DataSet ds = new DataSet();

da.Fill(ds);

return ds;

错误:期望参数@id未被提供

}



public DataSet FetchNextProducts(int productId,int recordsCount)

{

DataSet ds = new DataSet();

string query = string.Format(select top {0 } *来自tb_userdata内部联接tb_userlogin tb_userdata.uidfromtb1 = tb_userlogin.id其中tb_userlogin.id =@id ASC,recordsCount,productId);

SqlCommand cmd = new SqlCommand(query,con);

SqlDataAdapter adapter = new SqlDataAdapter(cmd);

adapter.Fill(ds);

return ds;

}

我怎么能克服这个



谢谢和问候

Hai all,
when i'm tying to develop the unlimited scrolling for my datalist i'm acing small problem can any one help me

if (Session["id"] != null)
{
mydb db = new mydb();
//Fetch 14 records initially.
DataSet dsProducts = db.GetProducts();
//Bind data to gridview
dl.DataSource = dsProducts;
dl.DataBind();
}

}
protected void btnGetMoreRecords_Click(object sender, EventArgs e)
{
mydb db = new mydb();
//Fetch 14 records initially.
DataSet dsProducts = db.FetchNextProducts(Convert.ToInt32(hiddenLastProductID.Value), 14);
//Bind data to gridview
dl.DataSource = dsProducts;
dl.DataBind();

error:expect parameter @id which was not suppled


}

public class mydb
{
private SqlConnection con;
public mydb()
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
}

public DataSet GetProducts()

{

SqlCommand cmd = new SqlCommand("select top 5 decription,url from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id where tb_userlogin.id=@id", con);
cmd.Parameters.AddWithValue("@id", id);

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
error:expect parameter @id which was not suppled
}

public DataSet FetchNextProducts(int productId, int recordsCount)
{
DataSet ds = new DataSet();
string query = string.Format("select top {0} * from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id where tb_userlogin.id=@id ASC", recordsCount, productId);
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds);
return ds;
}
how can i overcome this

Thanks and Regards

推荐答案

比较这两种方法:

Compare these two methods:
public DataSet GetProducts()
    {
    SqlCommand cmd = new SqlCommand("select top 5 decription,url from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id where tb_userlogin.id=@id", con);
    cmd.Parameters.AddWithValue("@id", id);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    return ds;
    }




public DataSet FetchNextProducts(int productId, int recordsCount)
    {
    DataSet ds = new DataSet();
    string query = string.Format("select top {0} * from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id where tb_userlogin.id=@id ASC", recordsCount, productId);
    SqlCommand cmd = new SqlCommand(query, con);
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    adapter.Fill(ds);
    return ds;
    }



第二个需要一个你没有提供的参数@id,而是试图将它连接到命令字符串 - 但是不太明白......

从String.Format中删除 productId ,并从第一个方法添加Parameter.AddWithValue行,但使用productId 而不是 id


The second one expects a parameter "@id" which you don't supply, instead you are trying to concatenate it into the command string - but not quite getting it there...
Remove the productId from the String.Format, and add the Parameter.AddWithValue line from the first method, but using productId instead of id


这篇关于期望参数@id不被提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆