I have a requirement to merge sql and csv data to data table.
Load part of sql table to dt table works fine... When I try csv read to dt, getting data types not match issue.
As I am new to c# , I do not know how to convert datatypes,
Can some one suggest and guide me to handle this scenario.
Thanks
Related
I have the following requirements:
I have many different database tables for example a table which shows different materialnumbers. There are many thousands rows in the database table (>100.000)
A user could import data with an excel file with thousends of rows.
The distinction/ difference between the excel file and the database-table should be added. The allready existing materialnumbers should be updated.
Is there a faster way than this to get the allready existing values in entity framework:
var allreadyExistingMaterialnumbersInDatabase = myDbContext.Materialnumbers.Where(x=>myExcelListMaterialnumbers.Contains(x.Materialnumber)).ToList();
After that step i have to do a update for all the data which is returned in the code example and then i have to insert all the difference between the list allreadyExistingMaterialNumbersInDatabase and myExcelListMaterialnumbers.
Thanks for your help.
I have json which the converted to Dataset. And this data I wanna written to table in SQl. But I don't know how this doing. I did tried doing through SqlBulkCopy but me this don't likes because that needed create other table. And data always different.Thanks.
I have HTML source and want to import specific tags from the HTML source to database-table " MySql " by using C#.
any suggestion would be great.
Your question is very abroad and we need some enlightment on your question, first off:
Do you have a database yet?
Do you have a connection with that database?
Have you set up a way to fire queries at that database?
Have you created a user that is allowed to fire queries at the database?
Why not save every unique column as a column in the database? pasting plain HTML into a database isn't really good practise.
Create a table named test_table with the column ID with an auto increment and a column data with the type longtext.
for the query:
INSERT INTO `test_table` (`data`) VALUES ('<a>someHTML code</a>')
I'm writing an C# application that watch for newly created xml files, and I want to insert some of the data in these XML files to a SQL database. One file is one row in the database.
What is the best and easiest way to do this?
What I have done so far is to defined a DataTable with the columns I want from the XML. After that I use ReadXML on the DataSet. This give me a DataSet with one table and one row, and the columns I want. So far it's perfect. But I can't find a good way to ONLY insert this new DataRow into my MSSQL database. I don't have any unique ID for that row yet. Would this make it easier? I don't want to map my dataset with the database, I'm only doing an insert...
You can do something like this to get the ID:
string query = "INSERT INTO Employees (EmployeeID, Name, Phone) "+
"OUTPUT INSERTED.EmployeeID "+
"VALUES (NEWID(), 'John Kris', '99-99999')";
Guid lastId = (Guid)command.ExecuteScalar();
The rest of the things you do sound ok for me.
I used LINQ to SQL to solve this. I set it up somewhat like described here:
LINQ to SQL.
On the data context I used InsertOnSubmit.
I have created one DataTable in C# dynamically. I want to insert this whole DataTable in MySql database table.
I am using MySql hence SqlBulkCopy is not an option for me.
I have tried MySqlBulkLoader but it seems it only insert data from file.
I can do it via iterating through every datarow of datatable and insert it to database.
Is there any another way I can achieve multiple inserts into database?
Thanks for any help!
If the number of rows are not much you can simply create an insert statement
INSERT INTO table VALUES (1,2,3), (4,5,6), (7,8,9);
Another article at http://www.codeproject.com/Articles/19727/ADO-NET-Generic-Copy-Table-Data-Function may help.
Though, if the number of rows are high, you can probably create a temporary text file and then use BulkLoader !