Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am getting the following error:
An Error Occured While getting Data From Hdr_AccountType.No mapping exists from object type System.Web.UI.WebControls.ListItem to a known managed provider native type.


Here is the function where I believe the error is occurring:
protected void btnSave_Click(object sender, EventArgs e)
    {
        Int32 st;
        int len = browser.PostedFile.ContentLength;
        byte[] pic = new byte[len];
        browser.PostedFile.InputStream.Read(pic, 0, len);

        SqlCommand Cmd = new SqlCommand();
        SqlConnection Cnn = new SqlConnection();
        string ConnectionString;
        ConnectionString = ConfigurationManager.ConnectionStrings["PhotostudioConnectionString"].ConnectionString;

        Cnn.ConnectionString = ConnectionString;
        if (Cnn.State != ConnectionState.Open)
            Cnn.Open();
        Cmd.Connection = Cnn;
        Cmd.CommandType = CommandType.StoredProcedure;
        Cmd.CommandText = "sproc_Ins_ManualPhotoSettingsDetails";
        Cmd.Parameters.Clear();
        // Cmd.Parameters.AddWithValue("@Id", txtBillNo.Text);
        Cmd.Parameters.AddWithValue("@Name", txtName.Text);
        Cmd.Parameters.AddWithValue("@Phoneno", txtPhoneno.Text);
        Cmd.Parameters.AddWithValue("@Startdate", rdpDate.SelectedDate); 
        Cmd.Parameters.AddWithValue("@Enddate", rdpDelivDate.SelectedDate);
        Cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
        SqlParameter Src = new SqlParameter("@FilePath", SqlDbType.NVarChar, 450);
        Src.Value = browser.PostedFile.FileName;
        Cmd.Parameters.Add(Src);
        Cmd.Parameters.AddWithValue("@Work", TextBox1.Text);
        Cmd.Parameters.AddWithValue("@Size", cmbSize.SelectedItem);
        Cmd.Parameters.AddWithValue("@Rate", txtRate.Text);
        Cmd.Parameters.AddWithValue("@Noofcopies", txtNoofcopies.Text);
        Cmd.Parameters.AddWithValue("@Total", txtTotal.Text);
        Cmd.Parameters.AddWithValue("@Paidamount", txtPaid.Text);
        Cmd.Parameters.AddWithValue("@Balance", txtbal.Text);



        try
        {
            st = Convert.ToInt32(Cmd.ExecuteScalar());

        }
        catch (Exception ex)
        {
            
            
            
                  
            
            throw new ApplicationException(
                "!!! An Error Occured While getting Data From Hdr_AccountType." + ex.Message);
            lblError.Visible = true;
            lblError.Text = "!!! An Error Occured While " + ex.Message.ToString();
            return;
        }



        Cmd.Dispose();

Any help is greatly appreciated.
Posted
Updated 16-May-11 23:57pm
v2

Depending on what your stored procedure returns - and I haven't a clue - I think you have confused the error reporting.
Rather than just blindly using Convert.ToInt32, try checking what type it is returning and cast it appropriately before attempting to convert.
 
Share this answer
 
Did you search for the error message?

Here is the Google search link - similar discussions[^].
 
Share this answer
 
I don't think this is the right function. The error is telling you that there's a mapping issue between a ListItem and a SQL data type - this function doesn't have any ListItem's in it (assuming that you aren't doing anything daft with your naming conventions).

The error output should include trace details of where the error really occurs. You need to use that information to identify where the error is happening.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900