ASP.Net:如何清除错误 [英] ASP.Net: How to clear an error

查看:127
本文介绍了ASP.Net:如何清除错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

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.

推荐答案

取决于您的存储过程返回的内容-我没有头绪-我认为您已经混淆了错误报告.
而不是仅盲目地使用Convert.ToInt32,而是尝试检查返回的类型并在尝试进行转换之前对其进行适当的转换.
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.


您是否在搜索错误消息?

这是Google搜索链接- ^ ].
Did you search for the error message?

Here is the Google search link - similar discussions[^].


我认为这不是正确的功能.该错误告诉您ListItem和SQL数据类型之间存在映射问题-此函数中没有任何ListItem(假设您对命名约定不做任何愚蠢的操作) ).

错误输出应包括真正发生错误的位置的跟踪详细信息.您需要使用该信息来确定错误发生的位置.
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.


这篇关于ASP.Net:如何清除错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆