2011-05-18 59 views
0

我已经设计我的网页的页面运行,但价值并不存储在数据库如何清除错误在asp.net

错误:

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

回答

3

这不是清算。 ..你要明白你为什么:

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

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

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