Aktham Mahmoud

Aktham Mahmoud

  • NA
  • 720
  • 35k

No mapping exists

Nov 8 2019 2:15 AM
Greeting
 
I faced this problem 
 
No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type 
 
here that code:
  1. protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)  
  2. {  
  3.      
  4.     try  
  5.     {  
  6.         using (SqlConnection sqlcon = new SqlConnection(connectionString))  
  7.         {  
  8.             if (e.CommandName.Equals("AddNew"))  
  9.             {  
  10.                 Label llbc = (Label)DetailsView1.FindControl("Lb_cat");  
  11.                 FileUpload fu = (FileUpload)DetailsView1.FindControl("FU_footer");                       
  12.                 if (fu.HasFile)  
  13.                 {  
  14.                     string fileName = fu.FileName;  
  15.                     string exten = Path.GetExtension(fileName);  
  16.                     //here we have to restrict file type              
  17.                     exten = exten.ToLower();  
  18.                     string[] acceptedFileTypes = new string[4];  
  19.                     acceptedFileTypes[0] = ".jpg";  
  20.                     acceptedFileTypes[1] = ".jpeg";  
  21.                     acceptedFileTypes[2] = ".gif";  
  22.                     acceptedFileTypes[3] = ".png";  
  23.                     bool acceptFile = false;  
  24.                     for (int i = 0; i <= 3; i++)  
  25.                     {  
  26.                         if (exten == acceptedFileTypes[i])  
  27.                         {  
  28.                             acceptFile = true;  
  29.                         }  
  30.                     }  
  31.                     if (!acceptFile)  
  32.                     {  
  33.                         lberrormsg.Text = "The file you are trying to upload is not a permitted file type!";  
  34.                     }  
  35.                     else  
  36.                     {  
  37.                         //upload the file onto the server                     
  38.                         fu.SaveAs(Server.MapPath("~/images/categories/" + fileName));  
  39.                         //Open Connection with D.B  
  40.                           
  41.                         sqlcon.Open();  
  42.                         string query = "INSERT INTO Products(P_Name,Ingredients,P_Price,P_photo) VALUES(@P_Name,@Ingredients,@P_Price,@P_photo)";  
  43.                         SqlCommand sqlcmd = new SqlCommand(query, sqlcon);  
  44.                           
  45.                         sqlcmd.Parameters.AddWithValue("@P_Name", (DetailsView1.FindControl("TB_Name"as TextBox).Text.Trim());  
  46.                         sqlcmd.Parameters.AddWithValue("@Ingredients", (DetailsView1.FindControl("TB_Ing"as TextBox).Text.Trim());  
  47.                         //sqlcmd.Parameters.AddWithValue("@P_Enable", Convert.ToBoolean (DetailsView1.FindControl("Ch_enabled") as CheckBox));  
  48.                         sqlcmd.Parameters.AddWithValue("@P_Price", (DetailsView1.FindControl("TB_Price"as TextBox).Text.Trim());  
  49.                         sqlcmd.Parameters.AddWithValue("@P_photo", fileName);  
  50.                         sqlcmd.Parameters.AddWithValue("@C_Id", (DetailsView1.FindControl("Lb_cat"as Label));  
  51.   
  52.                         sqlcmd.ExecuteNonQuery();  
  53.                         DetailsView1.DataBind();  
  54.                         lbsuccessmsg.Text = "New Record Added";  
  55.                         lberrormsg.Text = "";  
  56.   
  57.                     }  
  58.                 }  
  59.             }  
  60.         }  
  61.     }  
  62.     catch (Exception ex)  
  63.     {  
  64.   
  65.         lbsuccessmsg.Text = "";  
  66.         lberrormsg.Text = ex.Message;  
  67.     }  
  68. }  
  69.   
  70.   
  71. protected void DetailsView1_DataBound1(object sender, EventArgs e)  
  72. {  
  73.     DropDownList dr = (DropDownList)DetailsView1.FindControl("DDLCategory");  
  74.     Label lb1 = (Label)DetailsView1.FindControl("Lb_cat");  
  75.     lb1.Text = dr.SelectedItem.Value.ToString();  
  76. }  
So..what's wrong

Answers (1)