Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
425
Error: Requested record cannot be found by key when I change the SelectCommand of a DataSource
posted

I have this grid below

ig:WebDataGrid StyleSetName="Office2007Black" ID="WebDataGridNotas" runat="server" DataSourceID="AccessDataSourceNotas" ItemCssClass="borderClass"
Height="425px" Width="100%" AutoGenerateColumns="False" DataKeyFields="CodNotaMensal"

And I have the DataSource with a SelectCommand and an UpdateCommand that works fine when I am updating rows using client-side editing.

But when the user select a new value in a DropDownBox, I use this value to change the SelectCommand (just the WHERE clause) using codebehind triggered by the Change event of that DropDownBox. Then when I try to edit the same row I receive the "Requested record cannot be found by key"

Here is the CodeBehind

protected void WebDropDownDisciplina_SelectionChanged(object sender, Infragistics.Web.UI.ListControls.DropDownSelectionChangedEventArgs e)
{
notas.etapa = Convert.ToInt32(WebDropDownEtapa.SelectedValue);
notas.codUnidade = Convert.ToInt32(WebDropDownUnidade.SelectedValue);
notas.codGrau = Convert.ToInt32(WebDropDownGrau.SelectedValue);
notas.codSerie = Convert.ToString(WebDropDownSerie.SelectedValue);
notas.codTurma = Convert.ToString(WebDropDownTurma.SelectedValue);
notas.codDisciplina = Convert.ToInt32(WebDropDownDisciplina.SelectedValue);
notas.matriculaProfessor = Convert.ToInt32(WebDropDownProfessor.SelectedValue);
string selectCommand = "SELECT * FROM [NotasAvaliacaoSelect" + notas.etapa + "] WHERE ([NOTA-MENSAL].CodUnidade =" + notas.codUnidade + ") AND ([NOTA-MENSAL].CodGrau=" + notas.codGrau + ") AND ([NOTA-MENSAL].CodSérie='" + notas.codSerie + "') AND ([NOTA-MENSAL].Turma='" + notas.codTurma + "') AND ([NOTA-MENSAL].CodDisciplina=" + notas.codDisciplina + ") AND ([AULA].MatrículaProfessor=" + notas.matriculaProfessor + ") ORDER BY [NúmeroPauta]";
//string updateCommand = "UPDATE [NotasAvaliacaoUpdate" + notas.etapa + "] SET Faltas = ?, Avaliação1 = ?, Avaliação2 = ?, Avaliação3 = ?, Avaliação4 = ?, Avaliação5 = ?, Avaliação6 = ?, Avaliação7 = ?, Avaliação8 = ?, Avaliação9 = ?, Avaliação10 = ? WHERE (CodNotaMensal = ?)";
AccessDataSourceNotas.SelectCommand = selectCommand;
//AccessDataSourceNotas.UpdateCommand = updateCommand;
//AccessDataSourceNotas.DataBind();
WebDataGridNotas.ClearDataSource();
WebDataGridNotas.DataSourceID = AccessDataSourceNotas.ID;
WebDataGridNotas.DataKeyFields = "CodNotaMensal";
WebDataGridNotas.DataBind();
}

Parents Reply Children
No Data