Change IEnumerable To Datatable?
Dec 30, 2009
I used this but did not work :
Dim IENUM As IEnumerable = dat.getDanhSachDongSP
Dim bid as New BindingSource
bid.DataSource = IENUM
Dim dt2 As DataTable
dt2 = bid.DataSource
It show error "cant convert from IEnumberable to datatable"
View 4 Replies
ADVERTISEMENT
May 9, 2011
I have an object called Result<T> that has a constructor which accepts an argument of IEnumerable<T>. I'd like to be able to pass in a datatable if possible.
I tried datatable.AsEnumerable(), but where I bind to the data it was complaining that 'MyProperty' is not a field or property on type 'DataRow' - which makes sense since 'MyProperty' isn't a property on 'DataRow', but it was a column in my datatable.Is there a way to convert a datatable to something that I can pass into the Result object and still have it bind to, say, a gridview?
View 3 Replies
Dec 16, 2010
I tried using the linq Zip method on IEnumerable but it does not work for more than 2 arrays.Here is an example in Python of what I am trying to do(I got p - nested IEnumerable - and need q - another nested IEnumerable):
>>> l=['a','b','c']
>>> m=[1,2,3]
>>> n=['x','y','z'][code].......
View 2 Replies
Apr 24, 2012
Possibly a dup but I tried googling and searching here before posting. Assume a 2 column table with columns Age (int) and EmpName (string) A datatable can be converted to IEnumerable by a simple dbTable.AsEnumerable() Now to perform any Linq you must know the column names since intellisense will not pick it up due the fact that AsEnumerable has returned a bunch of datarows that you can enumerate. I have used a small 2 col table but for tables with many columns it is a pain. So most of the time we try something like
[Code]...
View 2 Replies
Jan 5, 2009
I have a datatable that I read xml into.
One of the columns is a date, but the dataype of that column is set to string. Is it possible to change that dataype to date?
View 10 Replies
Jun 21, 2010
I'm selecting value from my database, passing it to datatable then giving DataGridView.DataSource value of datatable.The thing is that in those rows i'm also selecting some dates and problem is that my default date in database is '1900-01-01 00:00:00' because i use "smalldatetime". And what i want is this...when I find default value in database i want to show it like an empty string, like i said...because date is in smalldatetime format i can't do this in SQL query so i wonder how can I change this in DataTable or even better in DataGridView...of course, in code?
View 4 Replies
Sep 7, 2011
I want to change the DataType of all columns of DataTable. I don't want use the loop.. [URL]
View 6 Replies
May 28, 2010
I have a datagridview bound to a datatable via a dataview. The user is allowed to edit cells in the datagridview, thereby editing cells in the datatable. I recently found that if the user editted a cell, then closed the form without ever clicking on a different cell (thereby causing the current cell to commit), the change was vanishing because the editted contents of the cell were not being saved back to the datatable.
This was only happening if the user closed the form. Clicking on any other control on the form also caused the cell changes to commit. After rooting abut in the DGV properties, it appeared that all I needed to do is add the following code to the Form Closing event handler:
If Me.dgvCurrentRedds.IsCurrentCellDirty Then
Me.dgvCurrentRedds.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
Sure enough, this caused the change to be registered in the underlying datatable. However, it was then getting obliterated by a different process, so I went looking for the source of that problem, and eventually tracked it down to this:
While the preceding code is causing the datatable to receive the new information, the datarow that has been changed still has the status Unchanged, even though it should have the status Modified since it actually has been modified. The fact that it appears unchanged causes some other code to obliterate the change, but that's irrelevant.
The question is, why is the row status UnChanged when it certainly has been Changed, and is there any sound way to force the row status to update?
View 2 Replies
Apr 9, 2012
I have a datatable contain fId field. I want to update all values for this field to "1" without using loop. [Code]
View 1 Replies
Dec 3, 2010
I am trying to set to autonumber, the column called "enregistrement" , that exists into different dataTables that I have.
vb.net
For TabIndex = 0 To oData.Tables.Count - 1
oData.Tables(TabIndex).Columns("enregistrement").Au
[code].....
View 6 Replies
Apr 12, 2011
I was wondering if there is a way to change the Fill command text of a datatable before issuing it.I need this because the table I am opening has over 15 thousand rows and it hangs for a while in the network when filling the table. So I would like to tell it what to SELECT instead of getting the whole table and then applying a filter.If there's a way of doing that without changing the fill command, it will also work for me.
View 2 Replies
Mar 3, 2008
I'm retooling an app, and condensing my queries down to one, but to do so, I would like to move the columns for better presentation. I am reporting on errors for particlular equipment, and the user may want to get equipment by errors or errors by equipment. Is there any way to change column order?
View 5 Replies
Jan 24, 2012
I'm pulling data from my DB, adding it to a DataTable and binding that DataTable to my DataGridView. Before I bind the data, I need to change/remove some data. When I loop through the rows and use a Select Case, just for this column, it doesn't work. But if I use an If, it works fine. [Code] In the example above, the "Pass_Flag" row works just fine, but the "FailureCD" does not. But after the Select, with the If statement, it works. In the example, I'm casting the row as a string first and then an integer. I tried casting to an integer in the select case and it doesn't work either.
View 4 Replies
Sep 11, 2009
I see a couple of previously answered questions about adding an item to an IEnumerable in C#, but I'm stuck when trying to implement the proposed solution in VB.NET.
Option Strict On
Dim customers as IEnumerable(Of Customer)
' Return customers from a LINQ query (not shown)
customers = customers.Concat(New Customer with {.Name = "John Smith"})
The above code gives the error:
Option Strict On disallows implicit conversions from Customer to IEnumerable(Of Customer)
View 2 Replies
May 25, 2009
is there a way to retrieve type T from IEnumerable<T> through reflection?
e.g.
i have a variable IEnumerable<Child> info; i want to retrieve Child's type through reflection
View 6 Replies
Jul 6, 2011
IEnumerable interface provides a instance method GetEnumerator that returns IEnumerator type opject .That's okey .But its very hezy to me that how IEnumerable objects are able to work with For Each loop ?When using For Each GetEnumerator method is not called directly from my code .Then from where and how GetEnumerator is called ?Basically my question is that when a class implements IEnumerabel interface then how a distinct behaviour is attached to that class?How it is used with For Each without calling GetEnumerator ?Here is the sample code that i am using :
Public Class Person
Public firstName As String
Public lastName As String
Public Sub New(ByVal firstName As String, ByVal lastName As String)
[code]....
View 3 Replies
Oct 26, 2011
i'm using Enumerable.Except to check if a DataTable in memory is in sync with the table in database.
The background is: this DataTable and other frequently used tables are stored in the Cache of a WebApplication. But meanwhile i'm convinced that this is not a good approach because it's a source for nasty errors that are difficult to reproduce/debug.
Therefore i've created a function that checks if database and memory are in sync, otherwise an error-log will be created. This works perfectly. If there is a row in memory that is not in database, this row will be shown below "Difference in database", the same applies in reverse. But if rows exist in both datasources(the PK idRMA) and some values differ, the log will contain this row in two versions(below "Difference in database" and "Difference in database"). It is not easy to see the differences on the first sight.
Q: Is it possible to select only the properties that caused Except to think that first sequence is not in second?
This is the the complete function(the first lines are relevant):
Public Shared Sub CheckRmaMemoryInSyncWithDB()
Dim inSyncText As String
Dim color As Drawing.Color
[Code]......
View 3 Replies
Apr 23, 2009
I'm trying to use the page control's collection with LINQ. Whereas this works:
dim l = Me.Controls.OfType(Of TextBox).AsQueryable()
the following return an ArgumentExceptionError:
dim l = Me.Controls.AsQueryable()
View 2 Replies
Aug 8, 2011
when you use the object browser to see the features of a sortedlist elementat is not shown , but because a sorted list inherets features of ienumerable it works, cant that be corrected
View 1 Replies
Jan 13, 2011
While learning to use LINQ in VB.NET, I came across the following:Dim x As IEnumerable = (some LINQ query)
If you can't instantiate an interface, but only a concrete implementation of it, why is this allowed? Is there some difference between doing Dim x as (Type) and Dim x as New (Type)?
View 1 Replies
Sep 2, 2009
I have an IEnumerable(Of System.Data.DataRowView) and would like to set it to be the datasource of a datagridview - however when I try I get no results my IEnumerable variable in the eg below is called xIEnum
DataGridView1.DataSource = xIEnum
However when I go
DataGridView1.DataSource = xIEnum.ToList
it works.... However I want the data to automatically update when I change the underlying datasource that the IEnum is mapped to?
View 5 Replies
Jan 22, 2010
I have the follow Linq query that is in a web application that was converted from .NET 1.1 to 3.5:
dim objListOfFilteredDataRows = from datarows as datarow in objDataSet.tables(0).rows _
where datarows("SomeColumn") = SomeValue
I have the exact same query in an application that was created using .NET 3.5 and the query returns an IEnumerable. However the query in the converted application is returning:
{Name = "WhereEnumerableIterator`1" FullName = "System.Linq.Enumerable+WhereEnumerableIterator`1[[System.Data.DataRow, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}
**Edit: When I highlight the expression, the intellisense says that it doesn't know the type of objListOfFilteredDataRows and assumes its a type of "Object". Why is the type not infered in the converted 1.1 application but is infered in the "native" 3.5?**
What am I missing here? How do I convert the "WhereEnumeratorIterator`1 to an IEnumerable?
View 5 Replies
Mar 1, 2012
I've searched everywhere for some example code for this, but I can't figure out how to bind data returned from a function that looks like this to a gridview or dataset.
Public Function GetCompanyList() As IEnumerable(Of BusinessUser)
Return (From companyList In CorporateLists
Select companyList.User).Distinct()
[code].....
View 1 Replies
Jun 17, 2011
how to insert records with dapper-dot-net. However, the answers, while informative, didn't seem to point me in the right direction. Here is the situation: moving data from SqlServer to MySql. Reading the records into an IEnumerable<WTUser> is easy, but I am just not getting something on the insert. First, the 'moving records code':
// moving data
Dim session As New Session(DataProvider.MSSql, "server", _
"database")
Dim resources As List(Of WTUser) = session.QueryReader(Of WTUser)("select * from tbl_resource")
[code]....
View 1 Replies
May 19, 2009
Suppose I have an IEnumerable such as a List(TValue) and I want to keep track of whether this list is being accessed (to prevent issues with, say, adding to the list while it is being iterated over on a different thread); I can always write code such as the following:
Dim List1 As New List(Of Integer)
Dim IteratingList1 As Boolean = False
' ... some code ... '
[Code]....
(I realize this code is very arbitrary, but it illustrates what I'm talking about.)
My question is whether there's a better/cleaner way to perform this check than by manually updating and accessing a Boolean, as above. I feel like there must be, but, to my knowledge, there isn't any IEnumerable class with a built-in "I am being iterated over" method or property. And writing a new class that implements IEnumerable and contains such a property seems like overkill to me.
View 3 Replies
Jun 5, 2012
In VB.Net you can easily get the text value of the first child element of an XElement like so:Dim sChildValue = xeParent.<MyChild>.Value()Of course that syntax is not supported in C#, but it produces the same IEnumerable(Of XElement) result as the Elements() method. So we can rewrite the above like so:
Dim sChildValue = xeParent.Elements("MyChild").Value()This Value() extension method is handy because often you are working with small XML documents and you just want the first node that matches. (One thing that annoys me about this method is that it seems to return Nothing/null if the IEnumerable list is empty due to the specified element not being found. To work around this I have created my own ValueOrBlank() method that returns an empty string in that situation instead.)
My problem is that I can't do the same thing in C#:var sChildValue = xeParent.Elements("MyChild").Value(); // won't compile, can't find Value() method
I checked my references/imports and they match the VB.Net project where the same call works. Fortunately I am able to use my custom ValueOrBlank() extension method to accomplish the same thing. But I'm curious as to what's missing in my C# project. I tried right-clicking on the Value() method call in Visual Studio and clicking "Go To Definition" to see if the Object Browser could tell me where the extension method is kept, but it just shows the System.String class. Does that mean this is one of those sneaky VB.Net-only features that the compiler itself supports, like the XML Axis < MyChild > syntax?
View 2 Replies
Sep 10, 2010
The following line is giving me an InvalidCastException when trying to convert to IEnumerable type, even though I have implemented IEnumerable interface. Return New CountryInfo(CountryCodes(i), CountryNames(i)) (also in bold below)
Imports System
Imports Gaia.WebWidgets.HtmlFormatting
Imports System.Collections.Generic
Imports System.Globalization
[code]....
View 1 Replies
Jun 11, 2009
If I have a List(Of x) and a List(Of y) is it possible to iterate over both at the same time?
Something like
for each _x as X, _y as Y in List(of x), List(of y)
if _x.item = _y.item then
'do something
end if
next
These lists may be of differing sizes. I am using .Net2.0 which I suspect is my downfall here as I have a feeling LINQ would solve something like easily by joining the lists on there common id.
View 7 Replies
May 12, 2011
This question is virtually the same as this SO post, only I'm looking for a VB.NET (.NET 4) solution. I've spun my wheels long enough trying to come up with a generic solution to solving this "power set" problem.
Dim choices As IEnumerable(Of String) = {"Coffee", "Tea", "Milk", "Cookies"}
Dim choiceSets = choices.CombineAll()
I'm looking for choiceSets to be an IEnumerable(Of IEnumerable(Of T)) so that I can do something like:
For each choiceSet in choiceSets
Console.WriteLine(String.Join(", ", choiceSet))
Next
[code]...
As you can see, this is every non-repeating combination from the source IEnumerable(Of T) (which could have 1 to many items in it - this example only had 4), it operates based on the order of the items in the source IEnumerable(Of T), and each item in the list is >= the previous item in terms of number of items in the inner IEnumerable(Of T).
For what it's worth, this is not homework; though it sure does feel like it. EDIT: Updated the example so it does not look like the result is alphabetically sorted, to stress that the source IEnumerable(Of T)'s existing order is used and added a 4th choice to clarify the sorting requirement within each set.
View 5 Replies
May 28, 2010
I've long since built a way around this, but it still keeps bugging me... it doesnt help that my grasp of dynamic LINQ queries is still shakey.
For the example:
Parent has fields (ParentKey, ParentField)
Child has fields (ChildKey, ParentKey, ChildField)
Pet has fields (PetKey, ChildKey, PetField)
[Code].....
The above Join call doesnt work. I sort of understand why it doesnt work, but hopefully it'll show you how I tried to accomplish this task.
After all this was done I would have appended a Select to finish the job.
I tried it with the PredicateBuilder with little success. I might not know how to use it right but it felt like it wasnt gonna handle the joining.
View 1 Replies