此方法通过jQuery调用并填充下拉框。它之前一直有效,直到我需要在下拉文本中添加一些额外的信息。我试图将ID传递到第二个存储过程中,并将该值放在我的KeyValuePair中的第一个值旁边。我不知道如何让这个ID传入。有什么想法吗?
[WebMethod]
//public static Dictionary<string, string> LoadRestByCityState(string city, string state)
public static List<KeyValuePair<string, string>> LoadRestByCityState(string city, string state)
{
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase(ConfigManager.AppSettings["ConnectionString.Data"]);
DbCommand dbCommand = db.GetStoredProcCommand("sel_RestByCityState_p");
db.AddInParameter(dbCommand, "@pCity", DbType.String, city);
db.AddInParameter(dbCommand, "@pState", DbType.String, state);
ds = db.ExecuteDataSet(dbCommand);
KeyValuePair<string, string> parks = new KeyValuePair<string, string>();
DataSet dset = new DataSet();
var list = new List<KeyValuePair<string, string>>();
list.Add(new KeyValuePair<string, string>("Select a restaurant", "0"));
foreach (DataRow row in ds.Tables[0].Rows)
{
DbCommand comm = db.GetStoredProcCommand("dbo.sel_RestDetailsByID_p");
db.AddInParameter(comm, "@pRestId", DbType.Int32, //keyvalueid );
db.AddInParameter(comm, "@pAttributeCode", DbType.String, "Detail");
dset = db.ExecuteDataSet(comm);
string attr = ds.Tables[0].Rows[0]["AttributeValue"].ToString();
list.Add(new KeyValuePair<string, string>(row[0].ToString() + " - " + attr, row[1].ToString()));
}
return list;
}
答案 0 :(得分:0)
你的问题是什么并不十分清楚,但我认为这一行
string attr = ds.Tables[0].Rows[0]["AttributeValue"].ToString();
应该阅读
string attr = dset.Tables[0].Rows[0]["AttributeValue"].ToString();
您正在查看外部数据集,而不是从存储过程返回的数据集。
任何帮助?
此外,您在调用存储过程时尚未创建KVP,因此您可以执行此操作
db.AddInParameter(comm, "@pRestId", DbType.Int32, row[0]); // or row[1], it isn't clear to me which you want to use.
答案 1 :(得分:0)