Results 1 to 5 of 5

Thread: C to VB.NET

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    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);}

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    Easier for me to understand...

  4. #4
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    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

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    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
  •  



Click Here to Expand Forum to Full Width