Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Hi sp returns 2 tables set record how to marge result set.
Result set table 1:
Result set table 2:
dtAll = new DataTable();
...
dtAll.Merge(dtOne);
dtAll.Merge(dtTwo);
dtAll.Merge(dtThree);
...
and so on.
This technique is useful in a loop where you want to iteratively merge data tables:
DataTable dtAllCountries = new DataTable();
foreach(String strCountry in listCountries)
{
DataTable dtCountry = getData(strCountry); //Some function that returns a data table
dtAllCountries.Merge(dtCountry);
}
If iam understanding you correctly
You wish to merge 2 identical data tables
dataTable.Merge(dataTable1);
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a MySQL Datatable with 3 columns : Name, X, Y
Let's say for now there's these values :
Basically I have a timer which loops through this Datatable and adds a new Button with Name, X, Y as it's location.
If I add a new row in my datatable, a new button will be created in the next timer's Tick event. Now how can I implement something to remove a button on the form which is not in the database anymore ?
Remember the list of buttons placed on the form. Then compare the list from the database and the list of buttons placed with Except.
Something like that:
IEnumerable<string> formButtons = ...;
IEnumerable<string> dbButtons = ...;
IEnumerable<string> buttonsToRemove = formButtons.Except(dbButtons);
buttonsToRemove now contains the buttons which are on the form, but not in the database anymore.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How to export csv to db in C#. It works fine when you have a plain text simple text. But in my case I need to parse headers as single row.
There are many options!
use some driver custom functions (depends on your database)
use a [schema.ini](
https://learn.microsoft.com/en-us/sql/odbc/microsoft/schema-ini-file-text-file-driver)
do it manually ...
You can do it manually with while iteration. Before using loop, you should read csv file from path with StreamReader.
For example:
using(var csvReader = new StreamReader(System.IO.File.OpenRead("your file path")))
{
while (!csvReader.EndOfStream)
{
var rows = csvReader.ReadLine();
var columns = rows.Split(';');
if(values.Length > 1)
{
// Your logic getting values to save db
}
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have comma-separated data in my column called col1, and I have an array of strings
IEnumerable<string> year = {"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000"}
I have tried the following
searchfrom = searchfrom.Where(x => years.Contains(x.col1.Replace(',', ' '))).ToList();
and
searchfrom = searchfrom.Where(x => years.Contains(x.col1)).ToList();
I want that row which is match any "year" into "col1"
To optimize such queries, you should first convert your years collection into a hash set.
var years = new HashSet<string>(new [] { "1990", "1991", ... });
In your Where clause, you need to split the contents of each of your records, x, for which you can use x.Split(','). Then, you need to check whether any of these subparts are contained within the years collection.
var result = searchfrom.Where(x =>
x.Split(',').Any(years.Contains)
).ToList();
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This is my table
ID SubID
============
1 1001
1 4432
1 2345
1 6322
2 2014
2 5432
The final result in treeview list should be
1
--1001
--4432
--2345
--6322
2
--2014
--5432
How to do that? Those data are stored in DataTable.
You can set the "key" of a node and check if it exists. If it doesn't, add it, then you can reference that key to add the child nodes:
foreach (DataRow dr in table.Rows) {
if (!treeView1.Nodes.ContainsKey(dr["ID"].ToString())) {
treeView1.Nodes.Add(dr["ID"].ToString(), dr["ID"].ToString());
}
treeView1.Nodes[dr["ID"].ToString()].Nodes.Add(dr["SubID"].ToString());
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to fetch all columns from the Users table, to store in holder as an array so that I can access all the rows from it. But the problem is when I put a breakpoint in the code, the holder variable only shows the value Webmatrix.Data.Database, why is that?
#{
var db = Database.Open("test");
var holder = db.QuerySingle("SELECT * FROM Users WHERE id = 1");
}
It's obviously wrong, so please correct my mistakes :) Thanks!
(edited to include the second double-quote that was in my actual code, but missed out in this question)
Your query is missing the closing double-quotes ("). The following will work:
#{
var db = Database.Open("test");
var holder = db.QuerySingle("SELECT * FROM Users WHERE id = 1");
}