Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:27:06+00:00 2026-06-05T09:27:06+00:00

basically i have a service which looks at two tables – one resides on

  • 0

basically i have a service which looks at two tables – one resides on a remote server, the other locally. I am trying to write a program which will select any required files from the remote server and copy them locally. i can get this working for standard records but how do i handle the blob in c# – i am just starting out with the language so be gentle

a snippet of what i have is below

public static void BroadcastCheck(String ip_addr)
    {
        OdbcConnection local = new OdbcConnection("DSN=local");
        OdbcConnection cloud = new OdbcConnection("DSN=cloud");
        local.Open();
        cloud.Open();
        OdbcCommand update1 = new OdbcCommand("UPDATE exchange set status = '1' where `status`='0' and inp_date=chg_date and LEFT(filename,12)='" + ip_addr + "' and type='UPDATE'", cloud);
        update1.ExecuteNonQuery();
        OdbcCommand broadcastSelect = new OdbcCommand("select * from exchange where inp_date=chg_date and LEFT(filename,12)='" + ip_addr + "' and status='1' and type='UPDATE'", cloud);
        OdbcDataReader DbReader = broadcastSelect.ExecuteReader();
        int fCount = DbReader.FieldCount;
        byte[] outByte = new byte[500]; 
        while (DbReader.Read())
        {
           String type = DbReader.GetString(0);
           String filename = DbReader.GetString(1);
           String data = DbReader.GetBytes(1);
           OdbcCommand broadcastCopy = new OdbcCommand("INSERT INTO exchange(type,filename) VALUES('"+type+"','"+filename+"'"+data+")", local);
           broadcastCopy.ExecuteNonQuery();


        }
        itouchcloud.Close();
        itouchlocal.Close();
        Console.Write("Broadcast Check Completed \n");

    }

Basically the cloud db is queried and may return multiple results, i want to process each record returned and copy it to the local DB.
i have looked around and cant seem to really get a decent solution, i can do this simply in Visual FoxPro 9 so im guessing there is a similar solution.

any help appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:27:07+00:00Added an answer on June 5, 2026 at 9:27 am

    The first part of the answer is, avoid dynamic SQL if you can. You’re using “… VALUES (‘”+type+”‘,'”+filename+”‘”+data+”)” when you should be using “… VALUES (?, ?, ?)”.

    Then, add the parameters using, for instance,

    // sample: the name of the parameter (here @Type) can be anything, and the type and length should match your schema.
    broadcastCommand.Parameters.Add("@Type", OleDbType.VarChar, 10).Value = type; 
    

    The question marks will be replaced by the parameters in the order you specify them, so you should add type, then filename, then data, in that order.

    Now, the value you specify should ALSO correspond to the type of field you are inserting into. So instead of String, String, String, you might want your variables to be of type String, String, byte[].

    There are about a million reasons not to construct your queries dynamically, so I would recommend studying up on how to use the Parameters collection on your OdbcCommand. Start here.

    UPDATE

    In general you can get DataReader values simply by using the indexer [], without needing to go through the GetXXX() methods. For byte arrays, that’s usually simpler, because you don’t need to know or try to guess the length beforehand.

    You can convert your code to use indexers this way:

    String type = (string)DbReader[0];
    String filename = (string)DbReader[1];
    byte[] data = (byte[])DbReader[2];
    

    Note that your GetBytes() call originally had a 1 in there, but I assume you aren’t trying to get the bytes of the filename field. So, if your byte[] data is in another field, use that instead. Be aware, however, that you could also use the string field names just as easily (and it might be clearer the next time you need to read the code):

    String type = (string)DbReader["type"]; // replace with whatever your fields are actually called
    String filename = (string)DbReader["filename"];
    byte[] data = (byte[])DbReader["data"];
    

    On the off-chance you had filename and data both using the same field because data isn’t actually in the database and instead you want to take the filename and read that filesystem object in as your data for the insert query, you’ll need to use a different method.

    byte[] data = System.IO.File.ReadAllBytes(filename); // requires .NET 2.0+
    

    Either way you fill your variables, insert them with a parameterized query as explained above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows Service which is basically accessing a mailbox and reading the
I have a Windows NT Service in C# which basically wakes up every x
I have a WCF service which basically returns [DataContract(IsReference = true)] public class Person
I have a windows service which basically consists of a FileSystemWatcher. This service works
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I am trying to implement a service with a public api which access control
I am creating an Installer for my application(which basically acts as an server). Now,
I have wrote a basic web service using .net which I intend to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.