Datagrid update 2
I have an sql file with key field Id (smallint) and fields Surname and Firstname. I display a datagrid to allow user to update the Surname and FirstName. Here is my code;
private void grdPlayers_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string Surname, FirstName;
string key = grdPlayers.DataKeys[e.Item.ItemIndex].ToString();
TextBox tb;
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
Surname = tb.Text;
tb = (TextBox)(e.Item.Cells[2].Controls[0]);
FirstName = tb.Text;
dsPlayers.PlayersRow r;
r = dsPlayers1.Players.FindById(smallint.Parse(key));
r.Surname = Surname;
r.FirstName = FirstName;
adptPlayers.Update(dsPlayers1);
grdPlayers.EditItemIndex = -1;
grdPlayers.DataBind();
}
but I get an error on line
r = dsPlayers1.Players.FindById(smallint.Parse(key));
saying cannot convert from int to short. Does anyone know what I can use here.
Also in the lines
dsPlayers.PlayersRow r;
r = dsPlayers1.Players.FindById(smallint.Parse(key));
can anyone explain why we are using dsPlayers when the only object I have defined is dsPlayers1?
Thanks.
Replies
Know the answer? Post it — somebody with the same question will find it here.