Wednesday, March 7, 2012

DataBinding: System.Data.DataRowView does not contain a property with the name RMID.

I m trying to UPDATE database using FormView and SqlDataSource and here is my code:

<

asp:SqlDataSourceID="sqlDS1"runat="server"ConnectionString="<%$ ConnectionStrings:myDB %>"UpdateCommand="UPDATE [Consultants] SET [firstName]=@.FIRSTNAME,[lastName]=@.LASTNAME,[skillCategoryID]=@.SKILLCATID,[resourceManagerID]=@.RMID,[AMgroupID]=@.AMGROUPID,[SkillSet]=@.SKILLSET,[statusID]=@.STATUSID,[location]=@.LOCATION,[comments]=@.COMMENTS,[profile]=@.PROFILE,[isAvailable]=@.ISAVAILABLE,[dateModified]=getdate(),[focusID]=1 WHERE ([id]=@.ID)">

<

UpdateParameters><asp:FormParameterFormField="txtFName"Name="FIRSTNAME"/><asp:FormParameterFormField="txtLName"Name="LASTNAME"/><asp:FormParameterFormField="ddlSkillCat"Name="SKILLCATID"/><asp:FormParameterFormField="ddlRM"Name="RMID"/><asp:FormParameterFormField="ddlAMGroup"Name="AMGROUPID"/><asp:FormParameterFormField="txtSkillset"Name="SKILLSET"/><asp:FormParameterFormField="ddlStatus"Name="STATUSID"Type="Int16"/><asp:FormParameterFormField="txtLocation"Name="LOCATION"/><asp:FormParameterFormField="txtComments"Name="COMMENTS"/><asp:FormParameterFormField="txtProfile"Name="PROFILE"/><asp:FormParameterFormField="cbAvailable"Name="ISAVAILABLE"/><asp:QueryStringParameterType="Int32"Name="ID"QueryStringField="id"/></UpdateParameters></asp:SqlDataSource>

//*******************************************************************

<

asp:FormViewDefaultMode="Edit"ID="FormView1"runat="server"DataSourceID="sqlDS1"DataKeyNames="id"><EditItemTemplate>

<

tr><tdclass="blacktextbold">

Resource Manager:

</td><tdclass="blacktext"><asp:DropDownListID="ddlRM"CssClass="blacktext"runat="server"DataSource="<%#GetRM()%>"DataTextField="RMName"DataValueField="userID"SelectedValue="<%#Bind('RMID')%>"AppendDataBoundItems="true"><asp:ListItemValue="-1">--Select RM--</asp:ListItem></asp:DropDownList><asp:CustomValidatorID="cvRM"runat="server"ValidationGroup="gpInsert"ControlToValidate="ddlRM"ClientValidationFunction="validateDropdown"OnServerValidate="servervalidateDropdown"Display="Dynamic"ErrorMessage="Required Field"CssClass="redtextsmallbold"/></td></tr>

//********************************************************

here is my GetRM() function:

protected

DataSet GetRM()

{

string strConnection =ConfigurationManager.ConnectionStrings["myDB"].ToString();SqlConnection objConnection =newSqlConnection(strConnection);String sqlSkillCats ="SELECT Roles.roleID, Roles.roleName, UsersInRoles.userID, UsersInRoles.roleID AS Expr1, Users.firstName + ' ' + Users.lastName AS RMName, Users.id AS Expr2" +" FROM Users INNER JOIN" +" UsersInRoles ON Users.id = UsersInRoles.userID CROSS JOIN" +" Roles" +" WHERE (Roles.roleName = 'accountmanager') AND (UsersInRoles.roleID = Roles.roleID) ORDER BY Users.firstName";SqlDataAdapter objAdapter =newSqlDataAdapter(sqlSkillCats, objConnection);

objConnection.Open();

//ddlDataSet = new DataSet();try

{

objAdapter.Fill(dsConsultantRM,

"ConsultantRM");

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

objConnection.Close();

return dsConsultantRM;

}

//******************************************************************

i get this error when i load the page:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'RMID'.

basically i m trying to UPDATE database using the value selected in the DropDownList, can anyone tell me whats wrong here...PLZ HELP!

I don't see a SelectCommand on your sqldatasource.|||

select command was in the function which returned the dataset. But that wasnt the issue, after changing all the CAPS parameter names to the exact name of the columns in my database i dint get any error!!!! i wonder why, for example i changed this:

<asp:parameter formfield="ddlRM" name="RMID"/>
TO
<asp:parameter formfield="ddlRM" name="resourceManagerID"/>

and then SelectedValue="<%#Bind('resourceManagerID')%>