datarow

Check Constraints on DataRow Add

DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("ValueOne",typeof(string)){AllowDBNull = false}); dt.Columns.Add(new DataColumn("ValueTwo",typeof(string)){AllowDBNull = false}); DataRow row = dt.NewRow(); row["ValueOne"] = "Test1"; if (dt.Rows.CanAdd(row)) { dt.Rows.Add(row); } Is ...

Simple way to convert datarow array to datatable

Hi.. I want to convert an datarow array into datatable.. Wat is the simple way to do this? Thanks in advance!! ...

About Marc Gravell's RowWrapperDescriptor for binding System.Data.Rows to PropertyGrid

Howdy, I came across Marc Gravell's elegant and witty solution to the problem posted by Matt ( title "C#/winforms: how to best bind a propertygrid and a System.Data.DataRow" ), and have used same solution in one of my applications. Using some excerpts from Marc's code : DataTable table = new DataTable(); table.Columns.Add("ID...

Suppress Crystal Reports section if there are no rows in a datatable

I have a section in a Crystal Report that I want to suppress. I need to suppress it if there are 0 rows in a particular table in the dataset I am using. How would I do this? The Record Number special field provided appears to be an internal count of records in the report, and does not relate to the rows in the underlying data table. I ...

Add new column and data to datatable that already contains data - c#

How do I add a new DataColumn to a DataTable object that already contains data? PseudoCode //call SQL helper class to get initial data DataTable dt = sql.ExecuteDataTable("sp_MyProc"); dt.Columns.Add("MyRow", type(System.Int32)); for(DataRow dr in dr.Rows) { //need to set value to MyRow column } ...

Object Reference Error filling a datarow

This is the code: Dim dr() As DataRow = DataSet.Tables("TableName").Select("EVENTNAME = '" & name & "'") I get an "Object reference not set to an instance of an object." Error when this line is executed. It is looping through a list of selected items in a listbox. I think it has to do with how I have the datarow declared because I c...

Why can't I do foreach (var Item in DataTable.Rows)?

Is there a reason why I can't do the following: foreach (var Item in DataTable.Rows) { rather than having to do foreach (DataRow Item in DataTable.Rows) { I would have thought this was possible, like it is on other datatypes. For example: foreach (var Employee in Staff) { // string[] Staff etc... When I try the first foreach loo...

C# DataRow Empty-check

I got this: DataTable dtEntity = CreateDataTable(); drEntity = dtEntity.NewRow(); Then I add data to the row (or not). Lots of code, really don't know if there's anything inside the row. Depends on the input (i am importing from some files). I'd like to do something like: if (drEntity`s EVERY CELL IS NOT EMPTY) { dtEntity.Rows...

Safely Removing DataRow In ForEach

I dont understand why I cannot do the below - This should work?? foreach (DataRow dataRow in dataTable.Rows) { if (true) { dataRow.Delete(); } } ...

Updating Cells in a DataTable

I'm writing a small app to do a little processing on some cells in a CSV file I have. I've figured out how to read and write CSV files with a library I found online, but I'm having trouble: the library parses CSV files into a DataTable, but, when I try to change a cell of the table, it isn't saving the change in the table! Below is the ...

silverlight datagrid row highlight dynamically

Hello, I have a datagrid populated with data and holding 8 columns. One of those column is "Verification Status". Now this "Verification Status" column contains Values "Yes" or "No". What I want to achieve is that when the grid is loading based on the values (Yes or No) I want to dynamically change the datagrid's row background color to...

vs2003: identify first row in DataRow[]

what is the best way to identify first row in the following code? foreach(DataRow row in myrows) { if (first row ) { ...do this... } else { ....process other than first rows.. } } ...

How to Assign a datarow object in .NET 1.1

currently I am doing this... object s = new object(); s = mydatarow["mycolumn"]; What I would like to do is... DataRow r = null; r = mydatarow["mycolumn"]; and I get an error saying that can not covert from object to DataRow. is there a better way of doing this? ...

Iterate through a DataTable to find elements in a List object?

As I iterate through a DataTable object, I need to check each of its DataRow objects against the items in a generic string List. I found a blog post using the List's Find method along with a delegate, but whereas that example has a separate class (Person), I'm attempting something like the following using an instance of the string objec...

How do I get column names to print in this C# program?

I've cobbled together a C# program that takes a .csv file and writes it to a datatable. Using this program, I can loop through each row of the data table and print out the information contained in the row. The console output looks like this: --- Row --- Item: 1 Item: 545 Item: 507 Item: 484 Item: 501 I'd like to print the column nam...

Check if DataRow exists by column name in c#?

I want to do something like this: private User PopulateUsersList(DataRow row) { Users user = new Users(); user.Id = int.Parse(row["US_ID"].ToString()); if (row["US_OTHERFRIEND"] != null) { user.OtherFriend = row["US_OTHERFRIEND"].ToString(); } ...

If I'm updating a DataRow, do I lock the entire DataTable or just the DataRow?

Suppose I'm accessing a DataTable from multiple threads. If I want to access a particular row, I suspect I need to lock that operation (I could be mistaken about this, but at least I know this way I'm safe): // this is a strongly-typed table OrdersRow row = null; lock (orderTable.Rows.SyncRoot) { row = orderTable.FindByOrderId(myOrd...

How to populate List<string> with Datarow values from single columns...

Hi, I'm still learning (baby steps). Messing about with a function and hoping to find a tidier way to deal with my datatables. For the more commonly used tables throughout the life of the program, I'll dump them to datatables and query those instead. What I'm hoping to do is query the datatables for say column x = "this", and convert th...

Is DataRow thread safe? How to update a single datarow in a datatable using multiple threads? - .net 2.0

Hello all I want to update a single datarow in a datatable using multiple threads. Is this actually possible? I've written the following code implementing a simple multi-threading to update a single datarow. I get different results each time. Why is it so? public partial class Form1 : Form { private static DataTable dtMain; pr...

How do I create a method that converts a DataRowCollection to an array of objects of a generic type in C#?

Hi, I am trying to create a method that takes a DataTable or a DataRowCollection and converts it to an array of a generic type. Something like this: public static T[] ConvertToArray<T>(DataTable dataTable) { List<T> result = new List<T>(); foreach (DataRow dataRow in dataTable.Rows) result.Add((T)dat...