datarow

C#/winforms: how to best bind a propertygrid and a System.Data.DataRow

给你一囗甜甜゛ 提交于 2020-01-09 19:12:08
问题 i have System.Data.DataRows with several fields, most of them just plain types like int, single, string. what is the best way to make them editable using a propertygrid? it should work automatically no matter what kind of fields the datarow has, but it should not display all of them. i want to provide a list of properties that should be hidden. since the DataTable is autogenerated i cannot add custom attributes like [Browsable(false)] thanks a lot! 回答1: Edited to handle filtering; much

C#/winforms: how to best bind a propertygrid and a System.Data.DataRow

隐身守侯 提交于 2020-01-09 19:11:31
问题 i have System.Data.DataRows with several fields, most of them just plain types like int, single, string. what is the best way to make them editable using a propertygrid? it should work automatically no matter what kind of fields the datarow has, but it should not display all of them. i want to provide a list of properties that should be hidden. since the DataTable is autogenerated i cannot add custom attributes like [Browsable(false)] thanks a lot! 回答1: Edited to handle filtering; much

How to check if a column with a given name exists in a datarow

允我心安 提交于 2020-01-03 13:50:11
问题 I want to insert a value from loop in datarow so before entering value in datarow, I want to check that a perticular column NAME exist in table or not. Please tell me how can I check it. (vb.net preferred). 回答1: I got the answer.and its working . its: If dr.Table.Columns.Contains("columnname") = True Then --your work--- End If 回答2: Try this Dim dt As New DataTable For Each dc As DataColumn In dt.Columns If dc.ColumnName = "" Then End If Next 回答3: try: if dr.Table.Columns("nameColumn") == null

Getting datarow values into a string?

大城市里の小女人 提交于 2020-01-01 01:12:11
问题 I have a dataset called "results" with several rows of data. I'd like to get this data into a string, but I can't quite figure out how to do it. I'm using the below code: string output = ""; foreach (DataRow rows in results.Tables[0].Rows) { output = output + rows.ToString() + "\n"; } However, I think I'm missing something because this isn't working. Can someone point me in the right direction? 回答1: You need to specify which column of the datarow you want to pull data from. Try the following:

How can I get a sum for the column “pieces” in a datatable?

微笑、不失礼 提交于 2020-01-01 00:46:11
问题 How can I get a sum for the column "pieces" in a datatable? Say I had the following table. How can I calculate the "total" pieces for article="milk" and artno="15"? Columns: article artno pieces Rows: 1 milk 15 1 2 water 12 1 3 apple 13 2 4 milk 15 1 5 milk 16 1 6 bread 11 2 7 milk 16 4 The Result of the my new DataTable should be this: Columns: article artno pieces Rows: 1 bread 11 2 2 water 12 1 3 apple 13 2 4 milk 15 2 5 milk 16 5 My Code: foreach (DataRow foundDataRow in foundRows1) { int

How to add new DataRow into DataTable?

北城以北 提交于 2019-12-31 10:19:34
问题 I have a DataGridView binded to a DataTable ( DataTable binded to database). I need to add a DataRow to the DataTable . I'm trying to use the following code: dataGridViewPersons.BindingContext[table].EndCurrentEdit(); DataRow row = table.NewRow(); for (int i = 0; i < 28; i++) { row[i] = i.ToString(); } But it doesn't work, DataGridView has never been added a new row. Please, tell me, how can I fix my code? Thank you in advance. 回答1: You can try with this code - based on Rows.Add method

How to add new DataRow into DataTable?

大憨熊 提交于 2019-12-31 10:19:08
问题 I have a DataGridView binded to a DataTable ( DataTable binded to database). I need to add a DataRow to the DataTable . I'm trying to use the following code: dataGridViewPersons.BindingContext[table].EndCurrentEdit(); DataRow row = table.NewRow(); for (int i = 0; i < 28; i++) { row[i] = i.ToString(); } But it doesn't work, DataGridView has never been added a new row. Please, tell me, how can I fix my code? Thank you in advance. 回答1: You can try with this code - based on Rows.Add method

Convert DataRow to Object with AutoMapper

余生长醉 提交于 2019-12-29 01:39:07
问题 I can successfully map from IDataReader to a List of objects but when I want to take one DataRow it doesn't seem to work as expected. Am I missing something simple here? [TestFixture] public class AutomapperTest { [Test] public void TestMethod1() { DataTable dt = new DataTable("contact"); dt.Columns.Add("FirstName"); dt.Columns.Add("LastName"); dt.Columns.Add("Line1"); dt.Columns.Add("Line2"); dt.Columns.Add("Line3"); dt.Columns.Add("Suburb"); dt.Columns.Add("State"); dt.Columns.Add("Postcode

How can I preempt the attempted assignment of DBNull to an int?

陌路散爱 提交于 2019-12-25 08:16:43
问题 The following code: foreach (DataRow fillRateDataRow in dtFillRateResults.Rows) { . . . var frbdbc = new FillRateByDistributorByCustomer { ShortName = fillRateDataRow["ShortName"].ToString(), Unit = fillRateDataRow["Unit"].ToString(), CustNumber = fillRateDataRow["Custno"].ToString(), MemberItemCode = fillRateDataRow["MemberItemCode"].ToString(), Qty = Convert.ToInt32(fillRateDataRow["Qty"]), QtyShipped = Convert.ToInt32(fillRateDataRow["QtyShipped"]), ShipVariance = fillRateDataRow[

C# getting values from DataTable or BindingSource

允我心安 提交于 2019-12-25 05:14:39
问题 I have a labels that need values retreieved from a Database. I am able to query the database but how can I extract values from a DataTable and place them in the appropiate labels Thanks 回答1: In DataTable you have rows and columns. To select a particular cell you need to do this: label1.Text = dataTable[0][0]; This will set the label1 text to Row 0, Column 0 value. To iterate through each row use: foreach(DataRow row in dataTable.Rows) { Console.WriteLine(row["ColumnName1"]); Console.WriteLine