datarow

Converting class object to datarow using LINQ in vb.net.

三世轮回 提交于 2019-12-24 21:29:05
问题 I have a list of class objects. I have a data table along with columns created. I need to insert all the data from the list into the data table. I am unable to get the LINQ right in vb.net. I have done the same using a for each loop, but i am looking out for the LINQ code. Sample code Private Function ToDataTable(ByVal sampleData As List(Of ClassA)) 'data table Dim dt As New DataTable 'add columns Dim column As DataColumn column = New DataColumn("Name") dt.Columns.Add(column) column = New

How can I select a row from a datatable using two variable values?

一笑奈何 提交于 2019-12-24 10:10:07
问题 Alright, so what I'm attempting to do here, is select from a datatable all the rows that match two variables. First, I queried a SPList into a datatable. The datatable has two columns, Client ID, and Model Details. Here's some of the code, so hopefully you can get an idea of what I'm attempting. //These are contained within a foreach loop, so will be different through each //iteration through. int iClientID = gdbData.GetClientID(iJobNumberID); string strModelDetails = xeApprovalUpdate

saving data in csv file

社会主义新天地 提交于 2019-12-23 06:31:12
问题 I have a problem to save data in .csv file. void WriteLog(DataRow rzad) { StreamWriter sw = new StreamWriter("log.csv", true); int iColCount = 8; for (int i = 0; i < iColCount; i++) { if (!Convert.IsDBNull(rzad[i])) { sw.Write(rzad[i].ToString()); sw.Write("\t"); } } sw.Write("\n"); sw.Flush(); sw.Close(); } The problem is tak in file I have data in A column. I want to smash one row in DataRow format to 8 parts, which are put in 8 different columns. My function working as it doesn't see the

Can you use DataTable.Contains(object key) if your datatable's primary key is two columns?

你。 提交于 2019-12-22 06:33:13
问题 if so how? 回答1: To select by a primary key you should use one of: DataTable.Rows.Find(Object) in case your PK is one column DataTable.Rows.Find(Object[]) in case you have more then 1 column as a primary key In case of a typed DataSet, the method MyDataTable.Rows.Find(...) will be generated for you with the proper signature. Basically it is a method on DataRowCollection class 回答2: 'Contains' does not seem to be a member of the DataRow class (maybe this is a typed data set?) In any case, you

How do I bind the result of DataTable.Select() to a ListBox control?

拜拜、爱过 提交于 2019-12-20 20:01:28
问题 I have the following code: ListBox.DataSource = DataSet.Tables("table_name").Select("some_criteria = match") ListBox.DisplayMember = "name" The DataTable.Select() method returns an array of System.Data.DataRow objects. No matter what I specify in the ListBox.DisplayMember property, all I see is the ListBox with the correct number of items all showing as System.Data.DataRow instead of the value I want which is in the "name" column! Is it possible to bind to the resulting array from DataTable

Getting a DataRow from an ASP.NET GridView

只谈情不闲聊 提交于 2019-12-20 01:38:36
问题 I have an ASP.NET GridView that's bound to an ObjectDataSource (which is bound to a MySQL database). On this grid, I have 2 unbound ButtonField columns that I want to trigger server-side events. Hence I have added an eventhandler method to the GridView 's RowCommand event. In the code of said eventhandler, I need to somehow get hold of the underlying DataRow that was clicked on by the user. However, I can't seem to get this to work; if I use code like the following the selectedRow variable is

DataRow: Select cell value by a given column name

早过忘川 提交于 2019-12-18 13:54:07
问题 I have a problem with a DataRow that I'm really struggling with. The datarow is read in from an Excel spreadsheet using an OleDbConnection. If I try to select data from the DataRow using the column name, it returns DBNull even though there is data there. But it's not quite that simple. datarow.Table.Columns[5].ColumnName returns "my column". datarow["my column"] returns DBNull. datarow[5] returns 500. datarow[datarow.Table.Columns[5].ColumnName] returns DBNull. (just to make sure its not a

DataColumn Name from DataRow (not DataTable)

耗尽温柔 提交于 2019-12-18 13:52:41
问题 I need to iterate the columnname and column datatype from a specific row. All of the examples I have seen have iterated an entire datatable. I want to pass a single row to a function to do a bunch of conditional processing. I want to separate the conditional processing for ease of readability. This is what I have: private void doMore(DataRow dr) { foreach (DataColumn c in dr.ItemArray) //loop through the columns. { MessageBox.Show(c.ColumnName.ToString()); } } The error returned is System

How I can search rows in a datatable with a searchstring?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 12:16:21
问题 I want to search rows in my DataTable . I've tried this: protected void imggastsuche_Click(object sender, EventArgs e) { string searchstring = txtgastsuche.Text; DataTable tb = DataBaseManager.GetDataTable(mysqlconnectionstring); DataRow[] foundRows = tb.Select("FIRSTNAME,LASTNAME,NAME,COMPANY,TIMEFROM,TIMETO,CREATOR Like '%" + searchstring + "%'"); tb = foundRows.CopyToDataTable(); this.ListView.DataSource = tb; this.ListView.DataBind(); } But I have an error in my string. What can I do if I

Safely Removing DataRow In ForEach

谁都会走 提交于 2019-12-17 22:44:08
问题 I don't understand why this code does not work. foreach (DataRow dataRow in dataTable.Rows) { if (true) { dataRow.Delete(); } } 回答1: Even though DataRow.Delete doesn't modify the state of the collection, Microsoft documentation states that you shouldn't call it while iterating over the collection: Neither Delete nor Remove should be called in a foreach loop while iterating through a DataRowCollection object. Delete nor Remove modify the state of the collection. The best solution is usually to