Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

GridView row updating using LINQ to SQL doesn't work

$
0
0

I have GridView that is filled with LINQ to SQL source. Here is the code

 protected void FillGridView()
        {


            DataClassesDataContext dContext = new DataClassesDataContext();

            Guid userId=(Guid)Membership.GetUser().ProviderUserKey;
            var Query = from p in dContext.users
                                     where p.userId==userId
                                       select new {...}//here are all the columns that are selected



            gvPregledi.DataSource = Query;
            gvPregledi.DataBind();
        }

protected void gvPregledi_RowEditing(object sender, GridViewEditEventArgs e)
{
gvPregledi.EditIndex = e.NewEditIndex;
DataBind();
}

protected void gvPregledi_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

TextBox tbBusy = (TextBox)gvPregledi.Rows[e.RowIndex].Cells[5].Controls[0];
TextBox tbuserName = (TextBox)gvPregledi.Rows[e.RowIndex].Cells[7].Controls[0];
TextBox tbuserSurname = (TextBox)gvPregledi.Rows[e.RowIndex].Cells[8].Controls[0];
TextBox tbNote = (TextBox)gvPregledi.Rows[e.RowIndex].Cells[9].Controls[0];
Guid recordId=new Guid(gvPregledi.Rows[e.RowIndex].Cells[0].Text);

var Query = from p in dContext.users
where p.recordId ==recordId
select p;

foreach (user p in Query)
{
p.Busy = tbBusy.Text;
p.Note = tbNote.Text;
p.userName = tbuserName.Text;
p.userSurname = tbuserSurname.Text;
try
{
dContext.SubmitChanges();
}
catch (Exception error)
{

//does not throw any exception
}
finally
{

}
}

This code does not throw any exception however does not update gridview neighter the database.Could someone help me?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>