• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 743
  • Last Modified:

copy / insert a binary field to a SQL Server Databaseusing "AddInParameter" in c# with Enterprise Library

Hi,
  While sync'ing a remote sql table to a local sql table, I have some stored procedures to select the data with a reader, then insert the data into the second local sql server database., everything was going great until I happened upon a table with binary data in it.

I'm using Microsoft Enterprise Library.

DbType.String, DbType.DateTime and DbType.Int32 fields work great
Just not sure how to do binary.  Any examples would be a great help!!!

Here is a code sample:
Thanks
Debug.WriteLine("Downloading Sec_Permissions");
            remoteCmd = m_remoteDb.GetStoredProcCommand("eVent_Sync_GetPermissionsDetail");
            m_remoteDb.AddInParameter(remoteCmd, "LastUpdated", DbType.DateTime, "01/01/1980"); //ToDo: Put in LastSync'd date here;
            using (IDataReader reader = m_remoteDb.ExecuteReader(remoteCmd))
            {
                while (reader.Read()) //ToDo: put in DbNull Checks for columns 1-3 as well.
                {   //GetString index is order of eVent_Sync_GetPermissionsDetail stored Procedure - 0 based...
                    DbCommand LocalInsUpdCmd = m_localDb.GetStoredProcCommand("eVent_Sec_AddUpdatePermission");
                    m_localDb.AddInParameter(LocalInsUpdCmd, "Permission", DbType.String, reader.GetString(0));
                    m_localDb.AddInParameter(LocalInsUpdCmd, "StringID", DbType.Int32, reader.GetInt32(1));
                    m_localDb.AddInParameter(LocalInsUpdCmd, "Description", DbType.String, reader.GetString(2));
                    //m_localDb.AddInParameter(LocalInsUpdCmd, "MAC", DbType.Binary, (reader[3]== DBNull.Value ? 0x00 : reader.GetBytes(3,0,)));
                    m_localDb.AddInParameter(LocalInsUpdCmd, "MAC", DbType.Binary, null); 
                    m_localDb.AddInParameter(LocalInsUpdCmd, "LastUpdated",DbType.DateTime, (reader[4] == DBNull.Value ? Convert.ToDateTime("01/01/1980") :  reader.GetDateTime(4)));
                    // reader[m_stationPrefs.JournalFieldSearchType] == DBNull.Value ? "" : (String)reader[m_stationPrefs.JournalFieldSearchType]

                    Debug.WriteLine(DLog.Log("eVent_Sec_AddUpdatePermission"), "Sync.Download_Sec_Permissions");

                    int numRecords = m_localDb.ExecuteNonQuery(LocalInsUpdCmd);
                    if (numRecords != 1)
                    {
                        throw new System.Data.DataException(numRecords.ToString() + " records inserted-Updated into evnt_Sec_Permissions Table: /n");
                    }
                    iInserted = iInserted + numRecords;
                    if ((iInserted % 2) == 0) //only bump counter every other record.
                    {
                        sa = new SyncArgs("PermissionRecord", iInserted);
                        //Raise the OnBumpCounter event.
                        OnBumpCounter(this, sa);
                    }
                } // while reader.read
            } //using IDataReader
            remoteCmd.Dispose();

            sa = new SyncArgs("PermissionRecord", iInserted);
            OnBumpCounter(this, sa);

Open in new window

0
carl-
Asked:
carl-
1 Solution
 
Todd GerbertIT ConsultantCommented:
Have a look here, let me know if it helps or not.
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_25735157.html 
0
 
carl-Author Commented:
Thanks!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now