Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 从SQL Server存储过程填充列表_Asp.net_Sql Server - Fatal编程技术网

Asp.net 从SQL Server存储过程填充列表

Asp.net 从SQL Server存储过程填充列表,asp.net,sql-server,Asp.net,Sql Server,希望这是一个快速解决方案,但我不能完全理解这一点我是一个新手,我有一段C代码,可以将数据发送到条带签出,这很好,问题是,如何从数据库动态填充SessionLineItemOptions protected void Page_Load(object sender, EventArgs e) { StripeConfiguration.ApiKey = ""; var options = new SessionCreateOptions {

希望这是一个快速解决方案,但我不能完全理解这一点我是一个新手,我有一段C代码,可以将数据发送到条带签出,这很好,问题是,如何从数据库动态填充SessionLineItemOptions

protected void Page_Load(object sender, EventArgs e)
{
    StripeConfiguration.ApiKey = "";

    var options = new SessionCreateOptions
    {
        SuccessUrl = "http://localhost:51835/secure/success.aspx?id={CHECKOUT_SESSION_ID}",
        CancelUrl = "http://localhost:51835/secure/cancel.aspx",
        PaymentMethodTypes = new List<string>{
            "card",
          },
        Mode = "payment",

        LineItems = new List<SessionLineItemOptions> {
    //getDataFromDataBase().ToList();
            new SessionLineItemOptions{
            Name = "Product 1",
            Amount = 4999,
            Currency = "gbp",
            Quantity = 1
        },
            new SessionLineItemOptions{
            Name = "Product 2",
            Amount = 12550,
            Currency = "gbp",
            Quantity = 1
        },
            new SessionLineItemOptions{
            Name = "Product 3",
            Amount = 9999,
            Currency = "gbp",
            Quantity = 1
        },
        },
    };

    var service = new SessionService();
    Session session = service.Create(options);
    sessionId = session.Id;
}
我试着把产品信息拿出来,但这是我遇到的问题,非常感谢你的帮助

public List<string> getDataFromDataBase()
{
    List<string> result = new List<string>();

    using (SqlConnection con = new SqlConnection("connectionStringHere"))
    {
        con.Open();
        DataTable tap = new DataTable();
        new SqlDataAdapter("SELECT * FROM mytable WHERE id = 'ABCDEFG'", con).Fill(tap);
        result = tap.Rows.OfType<DataRow>().Select(dr => dr.Field<string>("name")).ToList();
    }

    return result;
}

如果您花一点时间学习简单的ORM(如Dapper)更好,那么将数据表行转换为对象的所有痛苦都将消失。如果您花一点时间学习像Dapper这样的简单ORM,您可以在这里找到更好的方法,并且将数据表行转换为对象的所有痛苦都将消失。你可以在这里找到它