TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aktham Mahmoud
NA
720
37.7k
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:
protected
void
DetailsView1_ItemCommand(
object
sender, DetailsViewCommandEventArgs e)
{
try
{
using
(SqlConnection sqlcon =
new
SqlConnection(connectionString))
{
if
(e.CommandName.Equals(
"AddNew"
))
{
Label llbc = (Label)DetailsView1.FindControl(
"Lb_cat"
);
FileUpload fu = (FileUpload)DetailsView1.FindControl(
"FU_footer"
);
if
(fu.HasFile)
{
string
fileName = fu.FileName;
string
exten = Path.GetExtension(fileName);
//here we have to restrict file type
exten = exten.ToLower();
string
[] acceptedFileTypes =
new
string
[4];
acceptedFileTypes[0] =
".jpg"
;
acceptedFileTypes[1] =
".jpeg"
;
acceptedFileTypes[2] =
".gif"
;
acceptedFileTypes[3] =
".png"
;
bool
acceptFile =
false
;
for
(
int
i = 0; i <= 3; i++)
{
if
(exten == acceptedFileTypes[i])
{
acceptFile =
true
;
}
}
if
(!acceptFile)
{
lberrormsg.Text =
"The file you are trying to upload is not a permitted file type!"
;
}
else
{
//upload the file onto the server
fu.SaveAs(Server.MapPath(
"~/images/categories/"
+ fileName));
//Open Connection with D.B
sqlcon.Open();
string
query =
"INSERT INTO Products(P_Name,Ingredients,P_Price,P_photo) VALUES(@P_Name,@Ingredients,@P_Price,@P_photo)"
;
SqlCommand sqlcmd =
new
SqlCommand(query, sqlcon);
sqlcmd.Parameters.AddWithValue(
"@P_Name"
, (DetailsView1.FindControl(
"TB_Name"
)
as
TextBox).Text.Trim());
sqlcmd.Parameters.AddWithValue(
"@Ingredients"
, (DetailsView1.FindControl(
"TB_Ing"
)
as
TextBox).Text.Trim());
//sqlcmd.Parameters.AddWithValue("@P_Enable", Convert.ToBoolean (DetailsView1.FindControl("Ch_enabled") as CheckBox));
sqlcmd.Parameters.AddWithValue(
"@P_Price"
, (DetailsView1.FindControl(
"TB_Price"
)
as
TextBox).Text.Trim());
sqlcmd.Parameters.AddWithValue(
"@P_photo"
, fileName);
sqlcmd.Parameters.AddWithValue(
"@C_Id"
, (DetailsView1.FindControl(
"Lb_cat"
)
as
Label));
sqlcmd.ExecuteNonQuery();
DetailsView1.DataBind();
lbsuccessmsg.Text =
"New Record Added"
;
lberrormsg.Text =
""
;
}
}
}
}
}
catch
(Exception ex)
{
lbsuccessmsg.Text =
""
;
lberrormsg.Text = ex.Message;
}
}
protected
void
DetailsView1_DataBound1(
object
sender, EventArgs e)
{
DropDownList dr = (DropDownList)DetailsView1.FindControl(
"DDLCategory"
);
Label lb1 = (Label)DetailsView1.FindControl(
"Lb_cat"
);
lb1.Text = dr.SelectedItem.Value.ToString();
}
So..what's wrong
Reply
Answers (
1
)
Como trabajar con dos modelos en una vista
send data (string) trough ajax Calls to controller method