c# - The parameterized query '' expects the parameter '', which was not supplied -


i'm building application uses objectdatasource. want patient details displayed in gridview , once user selects record in it, want display data particular record in details view.

however have error in getpatientfulldetailsbypps

the parameterized query '(@pps nvarchar(4000))select * patients pps = @pps' expects parameter '@pps', not supplied.

c#:

public static patient getpatientfulldetailsbypps(string pps) {     patient patient = new patient();      //string cs = configurationmanager.connectionstrings["dbcs"].connectionstring;      using (sqlconnection con = new sqlconnection(getconnectionstring()))     {         sqlcommand cmd = new         sqlcommand("select * patients pps = @pps", con);         sqlparameter parameter = new sqlparameter();         parameter.parametername = "@pps";         parameter.value = pps;         cmd.parameters.add(parameter);         con.open();         sqldatareader dr = cmd.executereader(); --------> error here         while (dr.read())         {             patient.pps = dr["pps"].tostring();             patient.surname = dr["surname"].tostring();             patient.name = dr["name"].tostring();             patient.dob = dr["dob"].tostring();             patient.gender = dr["gender"].tostring();             patient.bloodgroup = dr["bloodgroup"].tostring();             patient.medicalcard = dr["medicalcard"].tostring();             patient.addressline1 = dr["addressline1"].tostring();             patient.addressline2 = dr["addressline2"].tostring();             patient.city = dr["city"].tostring();             patient.county = dr["county"].tostring();             patient.phone = dr["phone"].tostring();             patient.mobile = dr["mobile"].tostring();             patient.email = dr["email"].tostring();         }     }     return patient; } 

html:

<asp:gridview id="gridview2" runat="server" autogeneratecolumns="false" datasourceid="allpatientsobjectdatasource" width="759px" height="179px" style="margin-right: 15px" datakeynames="pps">                   <columns>                       <asp:boundfield datafield="pps" headertext="pps" sortexpression="pps" />                       <asp:boundfield datafield="surname" headertext="surname" sortexpression="surname" />                       <asp:boundfield datafield="name" headertext="name" sortexpression="name" />                       <asp:boundfield datafield="dob" headertext="dob" sortexpression="dob" />                       <asp:boundfield datafield="city" headertext="city" />                       <asp:commandfield buttontype="button" showselectbutton="true" />                   </columns>               </asp:gridview>            </td>           </tr>         <tr>             <td colspan="2">                 <asp:detailsview id="detailsview1" runat="server" autogeneraterows="false" datasourceid="patientsdetailsobjectdatasource" height="50px" width="125px">                     <fields>                         <asp:boundfield datafield="pps" headertext="pps" sortexpression="pps" />                         <asp:boundfield datafield="surname" headertext="surname" sortexpression="surname" />                         <asp:boundfield datafield="name" headertext="name" sortexpression="name" />                         <asp:boundfield datafield="dob" headertext="dob" sortexpression="dob" />                         <asp:boundfield datafield="gender" headertext="gender" sortexpression="gender" />                         <asp:boundfield datafield="bloodgroup" headertext="bloodgroup" sortexpression="bloodgroup" />                         <asp:boundfield datafield="medicalcard" headertext="medicalcard" sortexpression="medicalcard" />                         <asp:boundfield datafield="addressline1" headertext="addressline1" sortexpression="addressline1" />                         <asp:boundfield datafield="addressline2" headertext="addressline2" sortexpression="addressline2" />                         <asp:boundfield datafield="city" headertext="city" sortexpression="city" />                         <asp:boundfield datafield="county" headertext="county" sortexpression="county" />                         <asp:boundfield datafield="phone" headertext="phone" sortexpression="phone" />                         <asp:boundfield datafield="mobile" headertext="mobile" sortexpression="mobile" />                         <asp:boundfield datafield="email" headertext="email" sortexpression="email" />                     </fields>                 </asp:detailsview>             </td>         </tr>                     </table>              <asp:objectdatasource id="allpatientsobjectdatasource" runat="server" oldvaluesparameterformatstring="original_{0}" selectmethod="getpatients" typename="patientdb" dataobjecttypename="patient" deletemethod="deletepatient" ondeleted="objectdatasource1_deleted"></asp:objectdatasource>      <asp:objectdatasource id="patientsdetailsobjectdatasource" runat="server" oldvaluesparameterformatstring="original_{0}" selectmethod="getpatientfulldetailsbypps" typename="patientdb">         <selectparameters>             <asp:controlparameter controlid="gridview2" name="pps" propertyname="selectedvalue" type="string" />         </selectparameters>     </asp:objectdatasource> 

note: have set datanamekeys pps in gridview2.

make sure value parameter not null. must valid object or dbnull.value.

this terrible design choice microsoft, reason treat null value excluding parameter altogether. ado.net doesn't utilize generics guess that's excuse... somewhat. :)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -