如何清除asp.net中的错误

发布于 2024-11-08 03:42:38 字数 2250 浏览 1 评论 0原文

我已经设计了我的网页页面已运行但值未存储在数据库中

错误:

从 Hdr_AccountType 获取数据时发生错误。

不存在从对象类型 System.Web.UI.WebControls.ListItem 到已知托管提供程序本机类型的映射。

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();

I have designing my web page The page is run but value are not stored in database

The 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.

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薔薇婲 2024-11-15 03:42:38

这不是关于清理......你需要看看为什么你有:

不存在映射
对象类型 System.Web.UI.WebControls.ListItem 到已知托管提供程序本机类型。

我敢打赌,您需要使用 cmbSize.SelectedItem.Value 而不是 cmbSize.SelectedItem

顺便说一句,将数据库访问权限放在页面中是一个非常糟糕的概念,您应该创建一个仅用于处理数据库部分的类。

It's not about clearing ... you need to see why you have:

No mapping exists from
object type System.Web.UI.WebControls.ListItem to a known managed provider native type.

I would bet that you need to use cmbSize.SelectedItem.Value instead of cmbSize.SelectedItem

By the way, it's a very bad concept to put Database access in your pages, you should create a Class just for handling the database part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文