Solved

Database layer issue

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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