Solved

executing Stored procedure and error

Posted on 2006-11-21
3
226 Views
Last Modified: 2010-05-18
I am trying to execute the bewlo SP when the button1_click
occured, but I am geeting an error in CATCH statment and the number from daabase is not shown in the text box.

The error I am getting: when casting from number, the value must be a numbe less than infinity. Make sure the source type is convertible to the destination type.


public static int Acute_Treatment(int year, int month, string unit_abbr)
    {

        string connectionString = ConfigurationManager.ConnectionStrings["Finance_AppsConnectionString"].ConnectionString;
        System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);

        System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
        dbCommand.CommandText = "usp_Acute_Treatment";
        dbCommand.CommandType = CommandType.StoredProcedure;
        dbCommand.Connection = dbConnection;


        System.Data.IDataParameter dbParam_year = new System.Data.SqlClient.SqlParameter();
        dbParam_year.ParameterName = "@year";
        dbParam_year.Value = year;
        dbParam_year.DbType = System.Data.DbType.Int32;
        dbCommand.Parameters.Add(dbParam_year);



        System.Data.IDataParameter dbParam_month = new System.Data.SqlClient.SqlParameter();
        dbParam_month.ParameterName = "@month";
        dbParam_month.Value = month;
        dbParam_month.DbType = System.Data.DbType.Int32;
        dbCommand.Parameters.Add(dbParam_month);

        System.Data.IDataParameter dbParam_unitabbr = new System.Data.SqlClient.SqlParameter();
        dbParam_unitabbr.ParameterName = "@unit_abbr";
        dbParam_unitabbr.Value = unit_abbr;
        dbParam_unitabbr.DbType = System.Data.DbType.String;
        dbCommand.Parameters.Add(dbParam_unitabbr);
       

        int result = 0;

        try
        {
            dbConnection.Open();
            result = (int)dbCommand.ExecuteScalar();
        }
        catch
        {

        }


        finally
        {
            dbConnection.Close();
        }


        return result;


    }


  protected void Button1_Click(object sender, EventArgs e)
    {

        int month = Convert.ToInt32(DropDownList1.SelectedValue);
        int year = Convert.ToInt32(DropDownList2.SelectedValue);
        string unit_abbr = Convert.ToString(DropDownList3.SelectedValue);



        Acutetxt.Text = Convert.ToString(ActuteTreatments.Acute_Treatment(year, month, unit_abbr));

}
0
Comment
Question by:jung1975
3 Comments
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 250 total points
ID: 17988123
if the error is in this line: result = (int)dbCommand.ExecuteScalar();

then make a break point in it and verify what value is the stored returning
0
 

Author Comment

by:jung1975
ID: 17988793
it returns 0 , but I know the sp procudure should reture a value...
0
 
LVL 5

Assisted Solution

by:Collindsouza
Collindsouza earned 250 total points
ID: 18003845
jung1975

when u run the sp on its own.. does it retrieve any values???
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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 …

776 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