gpt4 book ai didi

c# - 如何从数据库表中提取浮点值并将其分配给 asp.net C# 中的 double 类型变量?

转载 作者:行者123 更新时间:2023-11-29 11:49:28 26 4
gpt4 key购买 nike

假设我有一个名为“Tabel1”的数据库表,其字段为“Id”、“用户名”、“x 坐标”、“y 坐标”。字段“x 坐标”和“y 坐标”的类型为 float。

如果我知道“Table1”上的用户名之一是“Michael”,我如何获取“SELECT x-coordinate FROM Tabel1 WHERE username = Michael”的结果并分配“x-coefficient”中的内容到名为 currentuserxcoord 的 double 类型变量?

我尝试仅在 asp.net 中使用 C# 来执行此操作。

最佳答案

将查询“从 Tabel1 WHERE username = Michael 中选择 x 坐标”分配给 SqlCommand 对象并使用 ExecuteScalar() 函数,如下所示

currentuserxcoord = Convert.ToDouble(sqlcmdobject.ExecuteScalar());

关于c# - 如何从数据库表中提取浮点值并将其分配给 asp.net C# 中的 double 类型变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377352/

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