473,657 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting JPEG images into an Access database using C# and ADO.NET

Hi,
I was trying to change an example for SQL Server to work with Access
db to insert image data. I have everything working except getting the
OleDbParameter type for the image column.

The table in access is :
img (
id number ,
name Text,
img number [Byte]
);

code :
===========
//....
byte[] photo = GetPhoto(photoF ilePath);
OleDbConnection Conn = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; User Id=;Data
Source=C:\\temp \\testdb.mdb");

OleDbCommand addJpg = new OleDbCommand("u pdate img set img =
@Photo where id = @id", Conn);

OleDbDataAdapte r MyDataAdapter = new OleDbDataAdapte r();

MyDataAdapter.I nsertCommand = addJpg ;

OleDbParameter id = new OleDbParameter ("@id", OleDbType.Integ er)
;
id.Value = 1;

OleDbParameter ph = new OleDbParameter ("@Photo",
OleDbType.VarBi nary, photo.Length) ;
ph.Value = photo;

MyDataAdapter.I nsertCommand .Parameters.Add (ph);
MyDataAdapter.I nsertCommand .Parameters.Add (id);

// connect
Conn.Open();
// insert
addJpg.ExecuteN onQuery();

Conn.Close();
//........

Any pointers...
Thanx in Advance
DN
Nov 15 '05 #1
4 22415
Hi,

Check out this article:
How to read and write a file to or from a BLOB column by using ADO.NET and
Visual C# .NET
http://tinyurl.com/2nvn5

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Deepankar" <dn********@wil liamoneil.com> wrote in message
news:c5******** *************** ***@posting.goo gle.com...
Hi,
I was trying to change an example for SQL Server to work with Access
db to insert image data. I have everything working except getting the
OleDbParameter type for the image column.

The table in access is :
img (
id number ,
name Text,
img number [Byte]
);

code :
===========
//....
byte[] photo = GetPhoto(photoF ilePath);
OleDbConnection Conn = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; User Id=;Data
Source=C:\\temp \\testdb.mdb");

OleDbCommand addJpg = new OleDbCommand("u pdate img set img =
@Photo where id = @id", Conn);

OleDbDataAdapte r MyDataAdapter = new OleDbDataAdapte r();

MyDataAdapter.I nsertCommand = addJpg ;

OleDbParameter id = new OleDbParameter ("@id", OleDbType.Integ er)
;
id.Value = 1;

OleDbParameter ph = new OleDbParameter ("@Photo",
OleDbType.VarBi nary, photo.Length) ;
ph.Value = photo;

MyDataAdapter.I nsertCommand .Parameters.Add (ph);
MyDataAdapter.I nsertCommand .Parameters.Add (id);

// connect
Conn.Open();
// insert
addJpg.ExecuteN onQuery();

Conn.Close();
//........

Any pointers...
Thanx in Advance
DN

Nov 15 '05 #2
Hi Miha,
Thx for the site. It helped to solve the problem.
Cheers
DN

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:<uo******* *******@tk2msft ngp13.phx.gbl>. ..
Hi,

Check out this article:
How to read and write a file to or from a BLOB column by using ADO.NET and
Visual C# .NET
http://tinyurl.com/2nvn5

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Deepankar" <dn********@wil liamoneil.com> wrote in message
news:c5******** *************** ***@posting.goo gle.com...
Hi,
I was trying to change an example for SQL Server to work with Access
db to insert image data. I have everything working except getting the
OleDbParameter type for the image column.

The table in access is :
img (
id number ,
name Text,
img number [Byte]
);

code :
===========
//....
byte[] photo = GetPhoto(photoF ilePath);
OleDbConnection Conn = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; User Id=;Data
Source=C:\\temp \\testdb.mdb");

OleDbCommand addJpg = new OleDbCommand("u pdate img set img =
@Photo where id = @id", Conn);

OleDbDataAdapte r MyDataAdapter = new OleDbDataAdapte r();

MyDataAdapter.I nsertCommand = addJpg ;

OleDbParameter id = new OleDbParameter ("@id", OleDbType.Integ er)
;
id.Value = 1;

OleDbParameter ph = new OleDbParameter ("@Photo",
OleDbType.VarBi nary, photo.Length) ;
ph.Value = photo;

MyDataAdapter.I nsertCommand .Parameters.Add (ph);
MyDataAdapter.I nsertCommand .Parameters.Add (id);

// connect
Conn.Open();
// insert
addJpg.ExecuteN onQuery();

Conn.Close();
//........

Any pointers...
Thanx in Advance
DN

Nov 15 '05 #3
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:<uo******* *******@tk2msft ngp13.phx.gbl>. ..
Hi,

Check out this article:
How to read and write a file to or from a BLOB column by using ADO.NET and
Visual C# .NET
http://tinyurl.com/2nvn5

Any chance you can post that url in a not tiny form?
Nov 15 '05 #4
Hi ,
I am trying to remove rows from a table using :
DataTable.Rows. RemoveAt(int index);
or
DataTable.Rows. Remove(DataRow row);
syntax.
I am able to run my test program successfully but none of the rows get
deleted. It works fine by using a delete SQL statement with a Command
object but I am trying to learn other methods todo the same. The
sample code : -

// dataset
DataSet ds = new DataSet() ;

// loads result set into dataset
oleDbDataAdapte r.Fill(ds);

// get the table; since we have only one table
DataTable workTable = ds.Tables[0];
// give it a name
workTable.Table Name = "coffee";
// how many rows do i have before removing
Console.WriteLi ne("Number of rows: {0}", workTable.Rows. Count );
for (int i=0; i < workTable.Rows. Count; i++)
{
DataRow myRow = workTable.Rows[i];
int sup_id = Convert.ToInt32 (myRow["sup_id"]);
if ( sup_id == 120 )
{
Console.WriteLi ne(sup_id);
workTable.Rows. RemoveAt(i);
workTable.Accep tChanges();
}
}

/***
foreach (DataRow myRow in workTable.Rows)
{
int sup_id = Convert.ToInt32 (myRow["sup_id"]);
if ( sup_id == 120 )
{
Console.WriteLi ne(sup_id);
workTable.Rows. Remove(myRow);
workTable.Accep tChanges();
}
}
*** /

// how many rows after removing
Console.WriteLi ne("Number of rows: {0}", workTable.Rows. Count );

}catch(OleDbExc eption e)
{
Console.WriteLi ne(e.StackTrace );
}
How do I commit the changes such that the rows are deleted from the
database;
Thx in advance
DN

dn********@will iamoneil.com (Deepankar) wrote in message news:<c5******* *************** ****@posting.go ogle.com>...
Hi Miha,
Thx for the site. It helped to solve the problem.
Cheers
DN

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:<uo******* *******@tk2msft ngp13.phx.gbl>. ..
Hi,

Check out this article:
How to read and write a file to or from a BLOB column by using ADO.NET and
Visual C# .NET
http://tinyurl.com/2nvn5

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Deepankar" <dn********@wil liamoneil.com> wrote in message
news:c5******** *************** ***@posting.goo gle.com...
Hi,
I was trying to change an example for SQL Server to work with Access
db to insert image data. I have everything working except getting the
OleDbParameter type for the image column.

The table in access is :
img (
id number ,
name Text,
img number [Byte]
);

code :
===========
//....
byte[] photo = GetPhoto(photoF ilePath);
OleDbConnection Conn = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; User Id=;Data
Source=C:\\temp \\testdb.mdb");

OleDbCommand addJpg = new OleDbCommand("u pdate img set img =
@Photo where id = @id", Conn);

OleDbDataAdapte r MyDataAdapter = new OleDbDataAdapte r();

MyDataAdapter.I nsertCommand = addJpg ;

OleDbParameter id = new OleDbParameter ("@id", OleDbType.Integ er)
;
id.Value = 1;

OleDbParameter ph = new OleDbParameter ("@Photo",
OleDbType.VarBi nary, photo.Length) ;
ph.Value = photo;

MyDataAdapter.I nsertCommand .Parameters.Add (ph);
MyDataAdapter.I nsertCommand .Parameters.Add (id);

// connect
Conn.Open();
// insert
addJpg.ExecuteN onQuery();

Conn.Close();
//........

Any pointers...
Thanx in Advance
DN

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2944
by: Pato Secruza | last post by:
Hi everyone! I have a really frustrating error and need help. I’m trying to do a function that gets the properties and names of the fields in a MS Access database using ASP. I haven’t programmed in a while so I’m quite lost. Once I have the my database structure I will insert the corresponding fields from a web form but the database is huge and I want to be able to change the database and form without changing the ASP code all the
2
1305
by: Shapper | last post by:
Hello, I am trying to insert a record in an Access database using Asp.Net/Vb.Net. I am getting the error: "Operation must use an updateable query." How can I solve this problem? The code I am using is:
2
1864
by: Avatar | last post by:
Hi: My team is developing a project where a client app needs to interact with a remote Access database using a Web Service. The client app, the Web Service and the database accessing layer are all implemented. The Access database works fine in the server machine but when we try to interact with it using the Web service, the database says "there are no permissions or the database is blocked". I think it is not a permissions problem...
0
1193
by: Burki | last post by:
Hi I want to know how to configure Access database using Enterprise Library Data block. I want to be able to spacify local path to mdb file in configuration file. I do not want users to creat DSNs, they should be able to connect any mdb file to application by updating configuration file. Best Regards Burki
1
3287
by: swatijogdand | last post by:
How to link table of sql server to access database using ado?
0
1176
by: swatijogdand | last post by:
Hi..... Again, it's really very urgent. does nebody have the code for connecting a SQL Server table to an access database using ADOX ??? Thanx in adavance, Regards, Swati
1
2153
by: 1064871 | last post by:
Hi How to insert Data in Microsoft Access database using VB.net regards adil
7
10446
by: mahipalerasani | last post by:
I am trying to connect to the Access database for querying, inserting and updating the data using 'C' API's. If somebody has code to connect to Access Database using C API's can you you please paste it here. Thanks in advance.
1
2608
by: Sunlis | last post by:
I need to find a way to communicate with a MS Access database using Javascript, PHP, or some other client-side scripting. It's for a Computer Science exam, and I cannot solve this problem. Users need to be able register using an html form, and then also be able to login. I know approximately zero javascript/php, and all I have as of now is a script that I found here earlier today, found here. ANY help would be greatly appreciated, as I've...
1
1692
by: arvindmishra | last post by:
i m inserting values in access database it displays message value is inserted but value is not ptresent in database. I m using following code OleDbConnection cnn = new OleDbConnection(); cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\medical.mdb"; cnn.Open(); string str = "insert into...
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.