SqlDataSource.Select()?我该如何使用这个? (ASP.net)

发布于 2024-10-29 01:06:28 字数 148 浏览 0 评论 0原文

我正在尝试使用 VB.NET 从 SQL 数据库检索值。如何使用SqlDataSource.Select()?有没有办法将值移至可用于其他用途的变量?

我知道它有点分散和模糊,但这是我能做的最好的事情。我基本上需要将标签文本设置为表中的值。

I'm trying to retrieve values using VB.NET from a SQL database. How do I use SqlDataSource.Select()? Is there a way to move the value to a variable that I can use for other things?

I know its kind of scattered and vague but that is the best I can do. I basically need to set a labels text to a value in a table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妄断弥空 2024-11-05 01:06:28

这会将结果查询放入数据表中。

DataView view = (DataView)dataSource.Select(new DataSourceSelectArguments());
DataTable groupsTable = view.ToTable();
String value;

foreach (DataRow dr in dt.Rows)
{
    // Do something here IE grab the value of the first column
    value = dr[0];
}

This puts the result query in to a DataTable.

DataView view = (DataView)dataSource.Select(new DataSourceSelectArguments());
DataTable groupsTable = view.ToTable();
String value;

foreach (DataRow dr in dt.Rows)
{
    // Do something here IE grab the value of the first column
    value = dr[0];
}
硬不硬你别怂 2024-11-05 01:06:28

回复评论中的最后一个问题:

YourTable.Rows(index)(index)
YourTable.Rows(index)("columnname")

Repying to last question in comment:

YourTable.Rows(index)(index)
YourTable.Rows(index)("columnname")
七堇年 2024-11-05 01:06:28

我疯狂地尝试执行这个简单的操作:

从 sqldatasource 检索数据并将其放入我可以操作的变量中。

最后,这里是为 VB.NET 执行此操作的后台代码:

Dim DV As New DataView()


Dim DataTable As New DataTable()

Dim SqlDataSource1 As New SqlDataSource()

Dim VALUE As String



SqlDataSource1.ID = "SqlDataSource1"
Me.Page.Controls.Add(SqlDataSource1)
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("Connection_name").ConnectionString


SqlDataSource1.SelectCommand = "SELECT * from Table"


DV = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)

DataTable = DV.ToTable()



For Each riga As DataRow In DataTable.Rows
    VALUE = riga("table_name").ToString


Next

foreach,在本例中仅获取第一个值,但您可以从数据表中获取任何值并将其放入向量中,或其他字符串,这样您就可以控制来自 sqldatasource 的数据。

享受

I was getting crazy trying to do this simple operation:

retrieving data from sqldatasource and put it into variables that I can manipulate.

At the end, Here the working behind code to do this for VB.NET:

Dim DV As New DataView()


Dim DataTable As New DataTable()

Dim SqlDataSource1 As New SqlDataSource()

Dim VALUE As String



SqlDataSource1.ID = "SqlDataSource1"
Me.Page.Controls.Add(SqlDataSource1)
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("Connection_name").ConnectionString


SqlDataSource1.SelectCommand = "SELECT * from Table"


DV = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)

DataTable = DV.ToTable()



For Each riga As DataRow In DataTable.Rows
    VALUE = riga("table_name").ToString


Next

the for each, in this case gets only the first value but you can get any value from datatable and put it into vector, or other strings, so you can control data coming from sqldatasource.

ENJOY

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文