|
-
Feb 10th, 2003, 01:44 PM
#1
Thread Starter
Frenzied Member
C to VB.NET
looking to see if someone can convert this C code to VB.NET. The code will download a BLOB from Oracle and place it on my harddrive...
void SqlBlob2File(String *DestFilePath)
{
try{
// The column number of the BLOB field.
int PictureCol = 0;
SqlConnection *cn = new SqlConnection("server=localhost;integrated security=yes;database=NorthWind");
SqlCommand *cmd = new SqlCommand("SELECT Picture FROM Categories WHERE CategoryName='Test'", cn);
cn->Open();
// Create server-side DataReader to read BLOB from database.
SqlDataReader *dr = cmd->ExecuteReader();
dr->Read();
// Create buffer for BLOB and read from DataReader. Close
// DataReader and Connection.
Byte b[] = __gc new Byte[Convert::ToInt32((dr->GetBytes(PictureCol, 0, 0, 0, Int32::MaxValue)))];
dr->GetBytes(PictureCol, 0, b, 0, b.Length);
dr->Close();
cn->Close();
// Open FileStream and write buffer to file.
FileStream *fs = new FileStream(DestFilePath, FileMode::Create, FileAccess::Write);
fs->Write(b, 0, b->Length);
fs->Close();
Console::WriteLine("SqlBlob2File completed successfully.\nPress return to continue.");
Console::ReadLine();
}catch(SqlException *ex)
{Console::Write(ex->Message);}
}
void OleDbBlob2File(String *DestFilePath)
{
try{
// The column number of the BLOB field.
int PictureCol = 0;
OleDbConnection *cn = new OleDbConnection("provider=SQLOLEDB;server=localhost;user id=user;password=pass;database=NorthWind");
OleDbCommand *cmd = new OleDbCommand("SELECT Picture FROM Categories WHERE CategoryName='Test'", cn);
cn->Open();
// Create server-side DataReader to read BLOB from database.
OleDbDataReader *dr = cmd->ExecuteReader();
dr->Read();
// Create buffer for BLOB and read from DataReader. Close
// DataReader and Connection.
Byte b[] = __gc new Byte[Convert::ToInt32((dr->GetBytes(PictureCol, 0, 0, 0, Int32::MaxValue)))];
dr->GetBytes(PictureCol, 0, b, 0, b.Length);
dr->Close();
cn->Close();
// Open FileStream and write buffer to file.
FileStream *fs = new FileStream(DestFilePath, FileMode::Create, FileAccess::Write);
fs->Write(b, 0, b->Length);
fs->Close();
Console::WriteLine("OleDbBlob2File completed successfully.\nPress return to continue.");
}catch(OleDbException *ex)
{Console::Write(ex->Message);}
-
Feb 12th, 2003, 07:52 PM
#2
Why do you want to convert it? Put it in a class, make a dll out of it and use it in VB.Net.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 14th, 2003, 08:08 AM
#3
Thread Starter
Frenzied Member
Easier for me to understand...
-
Feb 14th, 2003, 12:58 PM
#4
Lively Member
I wouldn't try to convert that per say, rather just learn how to establish a connection to that database and then query it into a recordset(or dataset) and then dump the field into a file..that should work.
toto
-
Feb 14th, 2003, 01:16 PM
#5
Thread Starter
Frenzied Member
after I get it into a dataset, how do I dump the field into a file?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|