Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to update the values with edit button. but unable to solve it.

the error is Specified cast is not valid in
C#
Var edt = (...);


protected void btnsubmit_Click1(object sender, EventArgs e)
    {
        int Clinicid = Convert.ToInt32(ViewState["ClinicID"]);
        string editPid = Request["editid"];
        var edt = (from ed in dc.dentist_addnewpatientmodifies
                   where ed.PatientID == editPid && ed.ClinicID == Clinicid
                   select ed).FirstOrDefault();
        edt.PName = txtfname.Text;
        edt.PMobileNo = txtmobile.Text;
        edt.PLandNo = txtphone.Text;
        edt.Ppincode = txtpincode.Text;
        edt.PEmailID = txtemail.Text;
    }
Posted
Updated 12-Mar-15 23:12pm
v3
Comments
Solai Raja 13-Mar-15 5:14am    
At Which line you are getting error?
It seems you are converting some invalid character to Int at first line
vickycode4 13-Mar-15 5:16am    
Error Line:
var edt = (from ed in dc.dentist_addnewpatientmodifies
where ed.PatientID == editPid && ed.ClinicID == Clinicid
select ed).FirstOrDefault();
Error is: Specified cast is not valid in
Solai Raja 13-Mar-15 5:23am    
Check the type of dentist_addnewpatientmodifies.PatientID and dentist_addnewpatientmodifies.CliniccID, both of the value type should be equal as you declare as int(Clinicid ) and string(editPid )
vickycode4 13-Mar-15 5:40am    
not worked. All the datatypes are of same type string.
Solai Raja 13-Mar-15 5:43am    
So ClinicID also string in you Entity right?
Make to your local variable(On button click event) editPid as string then try

Check the Datatype For "PatientID" and "editPid" both must be same,
Check the Datatype For "ClinicID" and "Clinicid" both must be same,
and editPid , Clinicid must be not null

C#
int Clinicid = ViewState["ClinicID"]==null?0: Convert.ToInt32(ViewState["ClinicID"]);

C#
string editPid =  string.IsNullOrEmpty(Request["editid"])?"":Request["editid"];
 
Share this answer
 
Comments
vickycode4 13-Mar-15 5:20am    
protected void btnsubmit_Click1(object sender, EventArgs e)
{
//int Clinicid = Convert.ToInt32(ViewState["ClinicID"]);
//string editPid = Request["editid"];

int Clinicid = ViewState["ClinicID"] == null ? 0 : Convert.ToInt32(ViewState["ClinicID"]);
string editPid = string.IsNullOrEmpty(Request["editid"]) ? "" : Request["editid"];
var edt = (from ed in dc.dentist_addnewpatientmodifies
where ed.PatientID == editPid && ed.ClinicID == Clinicid
select ed).FirstOrDefault();
edt.PName = txtfname.Text;
edt.PMobileNo = txtmobile.Text;
edt.PLandNo = txtphone.Text;
edt.Ppincode = txtpincode.Text;
edt.PEmailID = txtemail.Text;
}

But Same Error has Occured
vickycode4 13-Mar-15 5:55am    
Sorry not helped...!
[no name] 18-Mar-15 4:35am    
check
typeof(ed.PatientID)
typeof(ed.ClinicID)

type of editPid and typeof(ed.PatientID) must be same.
type of Clinicidand typeof(ed.ClinicID) must be same.
Quote:
where ed.PatientID == editPid && ed.ClinicID == Clinicid
According to the error, these data have different types. Please check and do appropriate changes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900