Solved

Database layer issue

Posted on 2006-07-06
2
234 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP:Radiobuttonlist/asp:RadioButtonListItem custom styling 1 44
Initial get page response times and IIS8 15 51
Output Caching in IIS 2 31
Problem to refer to value 8 51
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

825 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