SqlDataSource.Select ()? How to use it? (ASP.net)

I am trying to get values ​​using vb.net from sql database. How to use "SqlDataSource.Select ()"? Is there a way to move the value to a variable that I can use for other things?

I know it is scattered and vague, but this is the best I can do. I basically need to set the label text to a value in the table.

+6
sql database select
source share
3 answers

This puts the query of results in 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]; } 
+3
source share

Going to the last question in the comment:

  YourTable.Rows(index)(index) YourTable.Rows(index)("columnname") 
+3
source share

I was madly trying to do this simple operation:

extracts data from sqldatasource and puts them in variables that I can manipulate.

In the end, here is the working code for 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 

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

ENJOY

0
source share

All Articles