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();
    }

trying to debug..:)

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..

Show some of the code for dal().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.