1

I wonder what is the right approach for getting tables from dataset.

should i return the data within my procedure with select statement?

this is how i do it ,it works but i am not sure this is the right way.

SELECT SCOPE_IDENTITY()

and this is how i access my table:

ds.Tables[0].Rows[0][0]).ToString()
Maxim Toyberman
  • 1,906
  • 1
  • 20
  • 35
  • `SCOPE_IDENTITY()` is a scalar, not a table. Please explain what you are trying to do. – Dour High Arch Dec 02 '15 at 21:19
  • i am calling a procedure that creates a user,in my c# code i want to get the last number in my table, at first i tried to access my table like ds.Tables[0].Rows[0][0]).ToString() but then i realised that i get no table so i put SELECT SCOPE_IDENTITY() in my procedure – Maxim Toyberman Dec 02 '15 at 21:23
  • 2
    You do not want the “last number in my table” you want the ID of the inserted row. Use an `OUTPUT` clause as explained in [Best way to get identity of inserted row](http://stackoverflow.com/questions/42648/). – Dour High Arch Dec 02 '15 at 21:58

1 Answers1

0

You might want to try using DataRow and looping though the set

foreach(DataRow row in ds.Tables[0])
{
    string someData = row["keyname"].ToString();
}

I'm unsure of your question in the first place. But MSDN has a lot of ducumentation, and you can read up on more data structures that can help with DataTables and how to access them. And even query the DataTable with linq like this

var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;
Alex
  • 141
  • 1
  • 11