datarow

Simple way to convert datarow array to datatable

五迷三道 提交于 2019-11-27 09:34:03
问题 I want to convert a DataRow array into DataTable ... What is the simplest way to do this? 回答1: Why not iterate through your DataRow array and add (using DataRow.ImportRow, if necessary, to get a copy of the DataRow), something like: foreach (DataRow row in rowArray) { dataTable.ImportRow(row); } Make sure your dataTable has the same schema as the DataRows in your DataRow array. 回答2: For .Net Framework 3.5+ DataTable dt = new DataTable(); DataRow[] dr = dt.Select("Your string"); DataTable dt1

DataTable select method with single quote conflict C#

烂漫一生 提交于 2019-11-27 06:52:24
问题 I recently found when I do a LINQ select under a field that contains an apostrophe, it makes my application to throw an exception. DataRow[] newDr = this.ds.Tables["TableName"].Select("Name = '" + drData["Name"].ToString() + "'"); If drData["Name"] = "The business's money" I got an exception of "Syntax error: Missing operand after 'S' operator " Can anyone tell me how to preserve it and no replace it or remove it, please? 回答1: You have to escape the single quote to 2 single quotes, there may

Why ItemContainerGenerator.ContainerFromIndex() returns null and how to avoid this behavior?

爱⌒轻易说出口 提交于 2019-11-27 06:38:49
问题 I'm using this snippet to analyze the rows I've selected on a datagrid. for (int i = 0; i < dgDetalle.Items.Count; i++) { DataGridRow row = (DataGridRow)dgDetalle.ItemContainerGenerator.ContainerFromIndex(i); FrameworkElement cellContent = dgDetalle.Columns[0].GetCellContent(row); // ... code ... } The cycle runs smoothly, but when processing certain indexes, the second line throws a null exception. MSDN's documentation says that ItemContainerGenerator.ContainerFromIndex(i) will return null

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

限于喜欢 提交于 2019-11-27 06:25:20
问题 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 am creating the report from C#, but I cannot suppress the section from the code (it doesn't fit the project structure) - I must be able to do it from the report

How to add a button to a column in the DataGridView

白昼怎懂夜的黑 提交于 2019-11-27 02:43:46
问题 DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Software Title", typeof(string))); dt.Columns.Add(new DataColumn("Version", typeof(string))); dt.Columns.Add(new DataColumn("Uninstall", typeof(System.Windows.Forms.Button))); DataRow dr = dt.NewRow(); dr[0] = "App"; dr[1] = "1.0"; Button uninstall = new Button(); uninstall.Text = "Uninstall"; dr[2] = uninstall; dt.Rows.Add(dr); dataGridViewSoftware.DataSource = dt; The text appears but button never shows up. 回答1: Assuming you are

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

喜夏-厌秋 提交于 2019-11-27 01:57:21
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 loop, I get the the error CS0021: Cannot apply indexing with [] to an expression of type 'object' . Why can't the compiler figure out that .Rows returns a collections of DataRows? Rows effectively returns IEnumerable ( DataRowCollection ), so the compiler can only pick

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

♀尐吖头ヾ 提交于 2019-11-27 00:59:42
问题 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("NewColumn", type(System.Int32)); foreach(DataRow row in dr.Rows) { //need to set value to NewColumn column } 回答1: Just keep going with your code - you're on the right track: //call SQL helper class to get initial data DataTable dt = sql.ExecuteDataTable("sp_MyProc"); dt.Columns.Add("NewColumn",

Find row in datatable with specific id

一曲冷凌霜 提交于 2019-11-26 22:45:05
问题 I have two columns in a datatable: ID, Calls. How do I find what the value of Calls is where ID = 5 ? 5 could be anynumber, its just for example. Each row has a unique ID. 回答1: Make a string criteria to search for, like this: string searchExpression = "ID = 5" Then use the .Select() method of the DataTable object, like this: DataRow[] foundRows = YourDataTable.Select(searchExpression); Now you can loop through the results, like this: int numberOfCalls; bool result; foreach(DataRow dr in

Convert Access image OLE Object into raw image byte array in C#

落爺英雄遲暮 提交于 2019-11-26 19:09:38
I can't seem to get an answer all together for my real issue Invalid parameter when retrieving image from DB So Imma try piece by piece. Working with Visual Studio 2012 in C# and MS Access 2010. My solution is an app non-web related. I'm not sure about this part so here my question is on how to correctly get the image of an OLE Object that is in a row from a query into a byte array ( byte[] ), because certainly it isn't how I'm doing it with the following code. The row I'm talking about is row["FOTO"] . OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [APP_Equipamento_Geral]

difference between getting value from DataRow

有些话、适合烂在心里 提交于 2019-11-26 17:13:30
问题 Sample code: DataTable table = new DataTable(); // ... // insert column to table table.Columns.Add("name"); // ... // insert value to table foreach (DataRow row in table.Rows) { row["name"]; row.Field<string>("name"); } My question is: Is there a difference between using row["name"] and row.Field<string>("name") ? Of course, the second way cast value to some type, but is there another difference? Which method is better to use? 回答1: See Remarks section, main differences described there: The