473,836 Members | 1,434 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 22422
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
2964
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
1309
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
1871
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
1197
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
3298
by: swatijogdand | last post by:
How to link table of sql server to access database using ado?
0
1189
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
2215
by: 1064871 | last post by:
Hi How to insert Data in Microsoft Access database using VB.net regards adil
7
10457
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
2626
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
1700
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
9813
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
10541
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
10584
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
10248
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
7782
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
6976
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();...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4446
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
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.