0

How can I use the results of the select method in SqlDatasource like assign the returned id to a variable ?

1
  • i would not use SqlDataSource unless you are doing a quick&dirty tool or a throw-away-prototype. Commented Feb 22, 2011 at 20:20

1 Answer 1

1

By default the SqlDataSource returns a System.Data.DataView object from its select method:

System.Web.UI.WebControls.SqlDataSource source = new System.Web.UI.WebControls.SqlDataSource("Connection String", "Select Query");
System.Data.DataView view = (System.Data.DataView)source.Select(System.Web.UI.DataSourceSelectArguments.Empty);

The System.Data.DataView object is a collection of System.Data.DataRowView so if you wanted to get the value of "pk" column for the first object you do this:

int itemIndex = 0;
String ColumnName = "pk";
int ID = view[itemIndex][ColumnName];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.