0

I am currently using a datalist to update the database with a textbox control.
The problem is that when I am pressing "Edit" and entering values in the textbox and when trying to update the database, the database is not getting updated with the entered value.

Could someone please let me know the exact procedure to update the database with the value from the textbox?

<asp:DataList ID="DataList1" runat="server"  DataKeyField="memberID"  
       oneditcommand="DataList1_EditCommand" 
        onupdatecommand="DataList1_UpdateCommand">




private void   Load(){
         dal db = new dal();
        DataTable dt = new DataTable();
        dt = db.run_dr("SELECT [memberID], [Name], [Family], [Tell], [Email]);
        DataList1.DataSource = dt;
        DataList1.DataBind();





protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {
       TextBox txtName = (TextBox)e.Item.FindControl("TextName");
       TextBox txtFamily = (TextBox)e.Item.FindControl("TextFamily");
       TextBox txtTell = (TextBox)e.Item.FindControl("TextTell");

if (Page.IsValid)
        {
            db.run_dr("update members set Name=N'" + txtName.Text +
                                          "',Family=N'" + txtFamily.Text +
                                          "',Tell='" + txtTell.Text.Trim() +
                                          "' where  memberID="+                        DataList1.DataKeys[e.Item.ItemIndex].ToString());

            DataList1.DataBind();
            DataList1.EditItemIndex = -1;
        }
    }

Problem is the altered value in the textbox is not getting reflected

protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
    {

        DataList1.EditItemIndex = e.Item.ItemIndex;
        Load();
    }
5
Contributors
4
Replies
17
Views
5 Years
Discussion Span
Last Post by ggamble
0

Always Use parameterized Query when dealing with this kind of database operation.. This will reduce the chances of error to considerable extent..

Few Things to consider:

1> Check the Connection String
2> Check whether the database is correct.
3> Are You getting any errors in code.
4> Try to run the same update query in the database and see if this is working.
5> Debug to check the flow..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.