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 8244259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:47:26+00:00 2026-06-07T21:47:26+00:00

I am trying to make a generic update function for OracleDataAdapter , but it

  • 0

I am trying to make a generic update function for OracleDataAdapter, but it fails when I try to update the DataTable.
The Error message is Failed to convert value from a Int32 to a DateTime.
In the DataTable the values are fully formed DataTime values, so I don’t understand where the Update Commands fails… Any tips?

private void CreateUpdate()
{
    //UPDATE "TABLE" SET "AD_USERID" = :AD_USERID,  WHERE (("AD_USERID" = :Original_AD_USERID) AND ("MODULE" = :Original_MODULE))
    DataTable tbl = _DsViews.Tables[_DbName];
    string value = string.Empty;
    string where = string.Empty;
    foreach (DataColumn col in tbl.Columns)
    {
        value += string.Format("\"{0}\" = :{0},", col.ColumnName.ToUpper());
        where += string.Format("(\"{0}\" = :Original_{0}) AND ", col.ColumnName.ToUpper());
    }
    value = value.Substring(0, value.Length - 1);
    where = where.Substring(0, where.Length - 5);
    string sql = string.Format("UPDATE \"{0}\"  SET {1} WHERE ({2})", _DbName, value, where);
    ta.UpdateCommand = new OracleCommand(sql, MyDBConnection);

    foreach (DataColumn col in tbl.Columns)
    {
        var para1 = ta.UpdateCommand.Parameters.Add(col.ColumnName.ToUpper(), GetOraType(col.DataType));
        para1.SourceColumn = col.ColumnName;
        para1.SourceColumnNullMapping = col.AllowDBNull;

        var para2 = ta.UpdateCommand.Parameters.Add("Original_" + col.ColumnName.ToUpper(), GetOraType(col.DataType));
        para2.SourceColumn = col.ColumnName;
        para2.SourceVersion = DataRowVersion.Original;
        para2.SourceColumnNullMapping = col.AllowDBNull;
    }
}


OracleType GetOraType(System.Type type)
{

    switch (Type.GetTypeCode(type))
    {
        case TypeCode.Boolean:
        case TypeCode.Byte:
            return OracleType.Byte;
        case TypeCode.Char:
            return OracleType.Char;
        //case TypeCode.DBNull:
        //    return OracleType
        case TypeCode.DateTime:
            return OracleType.DateTime;
        case TypeCode.Decimal:
        case TypeCode.Double:
            return OracleType.Number;
        //case TypeCode.Empty:
        case TypeCode.Int16:
            return OracleType.Int16;
        case TypeCode.Int32:
            return OracleType.Int32;
        case TypeCode.Int64:
            return OracleType.Number;
        case TypeCode.Object:
            return OracleType.Blob;
        case TypeCode.SByte:
            return OracleType.SByte;
        case TypeCode.Single:
            return OracleType.Float;
        case TypeCode.String:
            return OracleType.NVarChar;
        case TypeCode.UInt16:
            return OracleType.UInt16;
        case TypeCode.UInt32:
            return OracleType.UInt32;
        case TypeCode.UInt64:
            return OracleType.Number;
        default:
            return OracleType.VarChar;
    }
}
  • 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-07T21:47:28+00:00Added an answer on June 7, 2026 at 9:47 pm

    Ms have a special way of handling null values, so we need to add params for them as well.
    This code will generate Update Commands for DataTables

        private void CreateUpdate()
        {
            //UPDATE "TABLE" SET "AD_USERID" = :AD_USERID,  WHERE (("AD_USERID" = :Original_AD_USERID) AND ("MODULE" = :Original_MODULE)) AND ((:IsNull_MODIFIED_BY = 1 AND ""MODIFIED_BY"" IS NULL) OR (""MODIFIED_BY"" = :Original_MODIFIED_BY))
            DataTable tbl = _DsViews.Tables[_DbName];
            string value = string.Empty;
            string where = string.Empty;
            foreach (DataColumn col in tbl.Columns)
            {
                value += string.Format("\"{0}\" = :{0},", col.ColumnName.ToUpper());
                if (GetOraType(col.DataType) == OracleType.Blob)
                    continue;
                if (col.AllowDBNull || col.DataType == typeof(DateTime))
                    where += string.Format("((:IsNull_{0} = 1 AND \"{0}\" IS NULL) OR (\"{0}\" = :Original_{0})) AND ", col.ColumnName.ToUpper());
                else 
                    where += string.Format("(\"{0}\" = :Original_{0}) AND ", col.ColumnName.ToUpper());
            }
    
            value = value.Substring(0, value.Length - 1);
            where = where.Substring(0, where.Length - 5);
            string sql = string.Format("UPDATE \"{0}\"  SET {1} WHERE ({2})", _DbName, value, where);
            ta.UpdateCommand = new OracleCommand(sql, MyDBConnection);
    
            foreach (DataColumn col in tbl.Columns)
            {
                ta.UpdateCommand.Parameters.Add(new OracleParameter(col.ColumnName.ToUpper(), GetOraType(col.DataType), 0, ParameterDirection.Input, col.ColumnName.ToUpper(), DataRowVersion.Current, false, null));
                if (GetOraType(col.DataType) == OracleType.Blob)
                    continue;
                if (col.AllowDBNull || col.DataType == typeof(DateTime))
                    ta.UpdateCommand.Parameters.Add(new OracleParameter("IsNull_" + col.ColumnName.ToUpper(), OracleType.Int32, 0, ParameterDirection.Input, col.ColumnName.ToUpper(), DataRowVersion.Original, true, null));
                ta.UpdateCommand.Parameters.Add(new OracleParameter("Original_" + col.ColumnName.ToUpper(), GetOraType(col.DataType), 0, ParameterDirection.Input, col.ColumnName.ToUpper(), DataRowVersion.Original, false, null));
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a generic function taking a variable argument list. A part
I am trying to make a generic Duplicate linq extension method. But I cannot
I've been trying and trying to make my generic extension methods work, but they
I have an extension method I'm trying to make generic, for message passing. public
I've been trying to make a generic class to represent a range of values
The problem I am trying to make a generic http module in asp.net C#
I have a page that I am trying to make a generic style of
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I'm trying to make an app I'm designing more generic and implement the command
Trying to make a custom :confirm message for a rails form that returns data

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.