Solved

Database layer issue

Posted on 2006-07-06
2
237 Views
Last Modified: 2008-02-01
Hello,

I am executing the stored procedures based on the following from by dataaccess layer. The issue is that some how it is not tackling null values. When I execute the stored procedure from the query analyzer it is working fine.

BUT when I execute from the ASP.net page I am getting an error saying input string was not in correct format.

Pls help

 /////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool InitialiseProcedure(string Procedure)
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        {
            // set the initial state preparatory to performing a stored procedure operation

            CloseReader();

            Command.Parameters.Clear();
            Command.CommandType = CommandType.StoredProcedure;
            Command.CommandText = Procedure;

            /* try
            {
                SqlCommandBuilder.DeriveParameters(Command);
            }
            catch (Exception Ex)
            {
                return false;
            }*/

            return true;
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void SetParam(string ParamName, object ParamValue, DbType dbType)
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        {
            // set the value of the specified parameter

            try
            {
                if (Command.Parameters.Contains(ParamName))
                    Database.SetParameterValue(Command, ParamName, ParamValue);
                else
                    Database.AddParameter(Command, ParamName, dbType, ParameterDirection.Input, "", DataRowVersion.Default, ParamValue);
            }
            catch (Exception Ex)
            {
                ReportError(Ex, "CommandText:[" + Command.CommandText + "] ParamName:[" + ParamName + "] ParamValue[" + ParamValue.ToString() + "]");
            }
        }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////And this is how I am executing the stored procedure

/////////////////////////////////////////////////////////////////////////////////////////////////////////
    public int LogRecipients()
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    {

        if (!Log || Db == null || Recipients.Count == 0)
            return -1;

        Db.InitialiseProcedure("z360core_insert_mail_message");

        Db.SetParam("@subject", Msg.Subject, System.Data.DbType.String);
        Db.SetParam("@recipient", Recipients[0].ToString(), System.Data.DbType.String);
        Db.SetParam("@sender", Msg.FromAddress, System.Data.DbType.String);
        Db.SetParam("@sender_name", Msg.FromName, System.Data.DbType.String);
        Db.SetParam("@message_id", Msg.MessageId, System.Data.DbType.String);
        Db.SetParam("@content_type", Msg.ContentType, System.Data.DbType.String);
        Db.SetParam("@email_date", System.DateTime.Now, System.Data.DbType.DateTime);
        Db.SetParam("@processed", System.DateTime.Now, System.Data.DbType.DateTime);
        Db.SetParam("@processed_by", App.UserId, System.Data.DbType.Int32);
        Db.SetParam("@ticket_number", TicketNumber, System.Data.DbType.Int32);

        //if (ParentMailMessageId != "")
            Db.SetParam("@mail_message_id", ParentMailMessageId, System.Data.DbType.Int32);

        int MailMessageId = int.Parse(Db.ExecuteScalarProcedure().ToString());

        if (MailMessageId < 0)
            return -1;

return MailMessageId;
    }


0
Comment
Question by:sureshraina
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17054591
What line the error is coming on?

Also look at the following code:

Title: Writing Data Access Layer
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20993347.html

-Nauman.
0
 
LVL 4

Accepted Solution

by:
davehunt00 earned 500 total points
ID: 17055336
My guess is it is one of the date fields, but you could try putting in some checks for null similar to what you have commented out:

if (ParentMailMessageId != "")

except use something like:

if (xyz is DBNull.Value) then xyz = ""

 Db.SetParam("@xyz", xyz, System.Data.DbType.String);

Of course, I'm not sitting in front of VS so check for syntax errors there...

Dave
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question