473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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(photoFilePath);
OleDbConnection Conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; User Id=;Data
Source=C:\\temp\\testdb.mdb");

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

OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();

MyDataAdapter.InsertCommand = addJpg ;

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

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

MyDataAdapter.InsertCommand .Parameters.Add(ph);
MyDataAdapter.InsertCommand .Parameters.Add(id);

// connect
Conn.Open();
// insert
addJpg.ExecuteNonQuery();

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

Any pointers...
Thanx in Advance
DN
Nov 15 '05 #1
4 22379
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********@williamoneil.com> wrote in message
news:c5**************************@posting.google.c om...
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(photoFilePath);
OleDbConnection Conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; User Id=;Data
Source=C:\\temp\\testdb.mdb");

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

OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();

MyDataAdapter.InsertCommand = addJpg ;

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

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

MyDataAdapter.InsertCommand .Parameters.Add(ph);
MyDataAdapter.InsertCommand .Parameters.Add(id);

// connect
Conn.Open();
// insert
addJpg.ExecuteNonQuery();

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**************@tk2msftngp13.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********@williamoneil.com> wrote in message
news:c5**************************@posting.google.c om...
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(photoFilePath);
OleDbConnection Conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; User Id=;Data
Source=C:\\temp\\testdb.mdb");

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

OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();

MyDataAdapter.InsertCommand = addJpg ;

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

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

MyDataAdapter.InsertCommand .Parameters.Add(ph);
MyDataAdapter.InsertCommand .Parameters.Add(id);

// connect
Conn.Open();
// insert
addJpg.ExecuteNonQuery();

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**************@tk2msftngp13.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
oleDbDataAdapter.Fill(ds);

// get the table; since we have only one table
DataTable workTable = ds.Tables[0];
// give it a name
workTable.TableName = "coffee";
// how many rows do i have before removing
Console.WriteLine("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.WriteLine(sup_id);
workTable.Rows.RemoveAt(i);
workTable.AcceptChanges();
}
}

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

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

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

dn********@williamoneil.com (Deepankar) wrote in message news:<c5**************************@posting.google. 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**************@tk2msftngp13.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********@williamoneil.com> wrote in message
news:c5**************************@posting.google.c om...
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(photoFilePath);
OleDbConnection Conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; User Id=;Data
Source=C:\\temp\\testdb.mdb");

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

OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();

MyDataAdapter.InsertCommand = addJpg ;

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

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

MyDataAdapter.InsertCommand .Parameters.Add(ph);
MyDataAdapter.InsertCommand .Parameters.Add(id);

// connect
Conn.Open();
// insert
addJpg.ExecuteNonQuery();

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
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...
2
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...
2
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...
0
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...
1
by: swatijogdand | last post by:
How to link table of sql server to access database using ado?
0
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
by: 1064871 | last post by:
Hi How to insert Data in Microsoft Access database using VB.net regards adil
7
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...
1
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...
1
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(); ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.