Extract images from SQL Server table - c#

I have a table that has 10M records and growing
in this table there is one fields called documentbody it is of type varchar(max)
in this field we store images data
this is way overload on the database
I would like to extract these images into a .jpg file and save them some where on the server instead of the database
the new jpg file will be named after each record index
e.g. 506613.jpg , 3177092.jpg , etc.
can I do that using SQL script? do I need .Net programming with that?

Related

Ho do I get return column value from Lookup to insert into Oledb destination db?

I am very new to SSIS: my requirement is to load the flat file with some columns (planid, name, start date, agentid), in flat file name column having with null, this name value i have to take from another sql db by help of fetching flat file planid. Finally this all values get to be insert into Oledb destination DB.
I worked with Lookup transformation,to return name column value from other SQL DB at the time of mapping in oledb dest db, it's throwing some errors even I used data conversion task. I don't know whether I am going with correct way or not.
flat file having =
100|null|3552|12/25/2018|
Other db having with=
100|Name:Patsy|
target to insert into OLE DB destination db:
100|Name:Patsy|3552|12/25/2018|

How to import html data to MySql

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>')

How do I display XML data in SQL in HTML

I am working on redesigning an old application that stored content in sql as xml data. I know that if I have a file I can use this to display the data in HTML:
xmlhttp.open("GET","xmlfile.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
Now, lets say I have a table in SQL. In a column I have the contents of "xmlfile.xml". How can I go about displaying that data?
Are you looking for specific field in the xml, SQL Server can query fields of a xml tag inside a sql server column row.
http://msdn.microsoft.com/en-us/library/ms345122(v=sql.90).aspx

How to store images in DB from DataGridView - C#?

I have DataGridView control in my form and the last column type is image.
How I can let the user select image in DataGridView and save it in the DB?
Thanks in advance.
Don't store the image itself in the DB bt in the filesystem and in tue DB store the images name only. This is a better option than stuffing data into DB blobs.
You can store arbitrary files in a SQL Server database by using a field with type BLOB ("Binary Large OBject"). Create a column of this type in your table, then you can load file data into it by referencing a file on the hard drive, probably using a stored procedure
There are quite a few articles on using BLOBS; here is a good-looking tutorial: Part one, part two.
Here is some sample code from that article that is specifically adding a BLOB value from a file:
INSERT INTO BLOBTest
(BLOBName, BLOBData)
SELECT 'First test file',
BulkColumn FROM OPENROWSET(
Bulk 'C:\temp\nextup.jpg', SINGLE_BLOB) AS BLOB
Whether or not you should do this is an entirely different question.

Insert records into a database from a hashtable

I'm looking for any advice on what's the optimum way of inserting a large number of records into a database (SQL2000 onwards) based upon a collection of objects.
Currently my code looks something similar to the snippet below and each record is inserted using a single sql simple INSERT command (opening and closing the database connection each time the function is called! - I'm sure this must slow things down?).
The routine needs to be able to cope with routinely inserting up to 100,000 records and I was wondering if there is a faster way (I'm sure there must be???). I've seen a few posts mentioning using xml based data and bulk copy routines - is this something I should consider or can anyone provide any simple examples which I could build upon?
foreach (DictionaryEntry de in objectList)
{
eRecord record = (eRecord)de.Value;
if (!record.Deleted)
{
createDBRecord(record.Id,
record.Index,
record.Name,
record.Value);
}
}
Thanks for any advice,
Paul.
Doing that way will be relatively slow. You need to consider a bulk INSERT technique either using BCP or BULK INSERT, or if you are using .NET 2.0 you can use the SqlBulkCopy class. Here's an example of using SqlBulkCopy: SqlBulkCopy - Copy Table Data Between SQL Servers at High Speeds
Here's a simple example for SQL Server 2000:
If you have a CSV file, csvtest.txt, in the following format:
1,John,Smith
2,Bob,Hope
3,Kate,Curie
4,Peter,Green
This SQL script will load the contents of the csv file into a database table (If any row contains errors it will be not inserted but other rows will be):
USE myDB
GO
CREATE TABLE CSVTest
(
ID INT,
FirstName VARCHAR(60),
LastName VARCHAR(60)
)
GO
BULK INSERT
CSVTest
FROM 'c:\temp\csvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
SELECT *
FROM CSVTest
GO
You could write out the dictionary contents into a CSV file and then BULK INERT that file.
See also: Using bcp and BULK INSERT
If you implement your own IDataReader method, you could avoid writing to an imtermediate file. See ADO.NET 2.0 Tutorial : SqlBulkCopy Revisited for Transferring Data at High Speeds
Related SO question: how to pass variables like arrays / datatable to SQL server?

Categories

Resources