-
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);}
-
Why do you want to convert it? Put it in a class, make a dll out of it and use it in VB.Net.
-
Easier for me to understand...
-
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
-
after I get it into a dataset, how do I dump the field into a file?