|
 |
aspx_beginners thread: C to VB.NET
Message #1 by "eyetalion" <eyetalion1@h...> on Mon, 10 Feb 2003 19:00:21
|
|
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);}
Message #2 by "Blue Tiger" <bluetiger@m...> on Mon, 10 Feb 2003 14:31:32 -0500
|
|
This should help:
http://www.aspalliance.com/aldotnet/examples/translate.aspx
Now if there only was a good VB.NET to C# translator, I would be a happy
camper.
-----Original Message-----
From: eyetalion [mailto:eyetalion1@h...]
Sent: Monday, February 10, 2003 7:00 PM
To: aspx_beginners
Subject: [aspx_beginners] 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);}
|
|
 |