gpt4 book ai didi

c# - 如何通过存储过程获取数据表

转载 作者:太空狗 更新时间:2023-10-29 22:15:21 27 4
gpt4 key购买 nike

以下是我的存储过程。

ALTER PROCEDURE SP_GetModels 
(
@CategoryID bigint
)
AS
BEGIN
Select ModelID,ModelName From Model where CategoryID=@CategoryID
END

我在后面的代码中调用存储过程

public SqlConnection conn;
public SqlDataReader GetModels()
{


DataTable dt = new DataTable();
public void DbConnection()
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SampleCs"].ConnectionString);
conn.Open();
}
DbConnection();
SqlCommand cmd = new SqlCommand("SP_GetModels", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@CategoryID", SqlDbType.BigInt, 10).Value = CategoryID;
// SqlDataAdapter madap = new SqlDataAdapter(cmd, conn);
SqlDataReader dreader= cmd.ExecuteReader();

//madap.Fill(dt);
return dreader;
}

我有一个下拉列表,我必须将包含模型名称的数据读取器对象绑定(bind)到该下拉列表。我如何将数据源设置为下拉列表作为数据读取器

最佳答案

private void PopDataBaseName()
{
try
{
SqlCommand cmd = new SqlCommand("sp_generate_report", con);
cmd.Parameters.Add("@TABLE_NAME", SqlDbType.VarChar,100).Value = TextBox1.Text;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);

}
catch (Exception ex)
{

}
}

关于c# - 如何通过存储过程获取数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1249091/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com