Hi,
I am trying to write some code to update/edit/delete records in a GridView but I am having problems. The GridView is populated through a stored procedure. Here is the code and the error I am getting. I have been doing searches over the net for the last two days and could not find an explanation that works. Can someone be so kind and explain me how can I write some code that will do just that?
Store Procedure (GetAgendaHoje)
SELECT CONVERT(VARCHAR(10), e.data_evento, 103) as Data, e.hora_evento Hora, c.nome Utilizador, e.local_evento Local, e.descricao Descrição, id_registo
from customers c, registo e
where e.data_evento = convert(char(10),getdate(),112)
order by 1,2,3
-----
<asp:GridView ID="dgAgenda" runat="server" AutoGenerateColumns="False"
BorderColor="Black" BorderStyle="Solid"
BorderWidth="2px" CellPadding="4" ForeColor="#333333"
OnRowDataBound="dgAgenda_RowDataBound"
datakeynames="id_registo"
Width="714px" style="text-align: left" onrowupdated="dgAgenda_UpdateCommand">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="Data" HeaderText="Data" />
<asp:BoundField DataField="Hora" HeaderText="Hora" />
<asp:BoundField DataField="Utilizador" HeaderText="Utilizador" />
<asp:BoundField DataField="Local" HeaderText="Local" />
<asp:BoundField DataField="Descri‡ão" HeaderText="Descri‡ão" />
<asp:BoundField DataField="id_registo" HeaderText="id_registo" ShowHeader="False" Visible="False"/>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" ShowHeader="True" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
-----
private
void inicializa()
{
SqlConnection conn = new SqlConnection(strLiga());
SqlCommand cmd44 = new SqlCommand("GetAgendaHoje", conn);
cmd44.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader dr2 = cmd44.ExecuteReader();
if (dr2.HasRows)
{
dgAgenda.DataSource = dr2;
dgAgenda.DataBind();
dr2.Close();
}
}
public void dgAgenda_UpdateCommand(object sender, GridViewUpdateEventArgs e)
{
SqlConnection conn = new SqlConnection(strLiga());
conn.Open();
SqlCommand cmd2 = new SqlCommand("updateRegisto", conn);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.Add("@date", SqlDbType.DateTime).Value = ((TextBox)dgAgenda.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
cmd2.Parameters.Add("@hora", SqlDbType.Time).Value = ((TextBox)dgAgenda.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
cmd2.Parameters.Add("@util", SqlDbType.VarChar, 250).Value = ((TextBox)dgAgenda.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
cmd2.Parameters.Add("@local", SqlDbType.VarChar, 250).Value = ((TextBox)dgAgenda.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
cmd2.Parameters.Add("@desc", SqlDbType.VarChar, 250).Value = ((TextBox)dgAgenda.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
cmd2.Parameters.Add("@id", SqlDbType.Int).Value = ((TextBox)dgAgenda.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
cmd2.ExecuteNonQuery();
conn.Close();
updateGrid();
dgAgenda.EditIndex = -1;
inicializa();
}
When I run the apps I get this error
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0123: No overload for 'dgAgenda_UpdateCommand' matches delegate 'System.Web.UI.WebControls.GridViewUpdatedEventHandler'