This question already has answers here:
How to get the identity of an inserted row?
(15 answers)
Closed 7 years ago.
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()
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;
Related
This question already has answers here:
Row numbers in query result using Microsoft Access
(7 answers)
Closed 4 years ago.
I am currently working on a C# .Net program. This program is connected to an MS Access database.
I am trying to select just one row from a table by specifying the row number, but I can not find any solution for that.
I hope you can help me with my problem :)
You should use primary key or unique column to get 1 row correct data. Other way is very manually and painfull in my opinion. Example
SELECT * FROM Customer WHERE CustomerID=1;
CostumerID is primary key and it bring 1 row to result. If do you realy want to make it manualy i advise add a datagridview in your project and make its visible to false. Fill your all data into it and get what do you want in it. You can access each row easyly.
This question already has answers here:
Distinct in Linq based on only one field of the table
(10 answers)
Closed 7 years ago.
In LINQ if the result that I have is the a list of whole records from the database and I want to do a Distinct on one column of this record, How do I do that?
You could try something as simple as:
var distincts = records.Select(x=>x.ColumnName).Distinct();
This question already has answers here:
Filling data at a particular location in a Data Table in C#
(3 answers)
Closed 8 years ago.
I have a Datatable like this.Now how can i pick the value from zones based on weight and zone.I am doing this in c#
Using LINQ Query : You need to use the AsEnumerable() extension for DataTable
var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;
AsEnumerable() returns IEnumerable. If you need to convert IEnumerable to a DataTable, use the CopyToDataTable()
Check Here
If you want to pick cells/rows with criteria. you need to a select clauase in your datatable. Go Here to see some examples
This question already has answers here:
Linq: Get a list of all tables within DataContext
(4 answers)
Closed 8 years ago.
I want to select list of all tables (Not columns) in a database using LINQ dynamically.
I just want it Dynamically not what listed in DataContext static values.For example i alter Table2 after deploying program. in this situation how i should find it.
By the way of there are any query also please let me know.
I think you can use the "Mapping" feature of LINQ:
context.Mapping.GetTables();
if you want to get tables that are modeled you can use #Mygyll answer, but if you want to list all tables in database you can use SMO, in smo when you have a database you can get all tables via this code
db.Tables.Cast<Table>()
This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
LINQ Between Operator
Dear All,
Hi,
I need to write this query in LINQ C#. can anyone help me?
Select *
From Mytable
where MyText BETWEEN 'john' AND 'Pear'
I believe this query should work:
var results = yourTable.Where(x => x.Text.CompareTo("john") > 0 &&
x.Text.CompareTo("Pear") < 0);
This assumes that you want to compare the text in each row of the table, and not some pre-dfined string.
Here is how you can do it with ObjectQuery
MytableSet.Where("it.Name between #start and #end", new ObjectParameter("start", "john"), new ObjectParameter("end", "Pear"))
EDIT:
Forget to mention that this statement is specific to Entity Framework not LINQ2SQL.