troubleshooting Question

Update using c# and LINQ to SQL

Avatar of PITBULL72
PITBULL72Flag for United States of America asked on
.NET ProgrammingC#ASP.NET
5 Comments1 Solution311 ViewsLast Modified:
Hello, been trying to update my table using LINQ to SQL via C#. I'm able to insert new records, but I cant edit them, plus i'm having issues again with the date and time.

My code is below.

Thanks

P

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;


public partial class Search : System.Web.UI.Page
{
    LDDataClassesDataContext db = new LDDataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.Visible = true;
        getdata();
    }
   
    protected void BtnSrch_Click(object sender, EventArgs e)
    {
       
    }
    protected void BtnReset_Click(object sender, EventArgs e)
    {
        GridView1.Visible = false;
        GridView1.DataBind();
        DtRcvTxt.Text = null;
        RqAgy.SelectedIndex = -1;
        RnkReqAgy.SelectedIndex = -1;
        LnamReqAgy.Text = null;
        LdTxtbx.Text = null;
        LrTxtbx.Text = null;
        CmplntTxt.Text = null;
        CmntsTxt.Text = null;
        CoDDL.SelectedIndex = -1;
        SbmtTxt.Text = null;
        Cse.Text = null;
        LgTxt.Text = null;
        DtReqFx.Text = null;
        GrpDDL.SelectedIndex = -1;
        RnkRecReqDDL.SelectedIndex = -1;
        LnamRecAgy.Text = null;
        FivDDL.SelectedIndex = -1;
        OGtxt.Text = null;
     }

    protected void BtnUpdt_Click(object sender, EventArgs e)
    {
        var qry = from m in db.LDRFs
                  where m.ID == Convert.ToInt32(Request.QueryString["ID"])
                  select m;
        foreach (var q in qry)
        {
            q.LnamRec = LnamRecAgy.Text;
            q.LglReq = LgTxt.Text;
            //q.DtAgyRqRec = DateTime.TryParse(DtRcvTxt.Text, out dt) ? dt : (DateTime?)null;
            //q.SubmtBy = DateTime.TryParse(SbmtTxt.Text, out dt) ? dt : (DateTime?)null;
            //q.DtReqFx = DateTime.TryParse(DtReqFx.Text, out dt) ? dt : (DateTime?)null;
            q.ReqAgy = RqAgy.SelectedItem.Text;
            q.RnkReq = RnkReqAgy.SelectedItem.Text;
            q.LnamReq = LnamReqAgy.Text;
            q.LwDpt = LdTxtbx.Text;
            q.LglReq = LrTxtbx.Text;
            q.Cmplnt = CmplntTxt.Text;
            q.Cmnt = CmntsTxt.Text;
            q.CrtOrdr = CoDDL.SelectedItem.Text;
            q.Case_ = Cse.Text;
            q.Log_ = LgTxt.Text;
            q.Grp_ = GrpDDL.SelectedItem.Text;
            q.RnkRec = RnkRecReqDDL.SelectedItem.Text;
            q.LnamRec = LnamRecAgy.Text;
            q.Finv = FivDDL.SelectedItem.Text;
            q.OG_ = OGtxt.Text;
            Response.Redirect("Update.aspx");
        }
        db.SubmitChanges();
    }
    void getdata()
    {
        var qry = from m in db.LDRFs
                  where m.ID == Convert.ToInt32(Request.QueryString["ID"])
                  select m;
        foreach (var q in qry)
        {
            LnamRecAgy.Text=q.LnamRec;
            LgTxt.Text = q.LglReq;
            //q.DtAgyRqRec = DateTime.TryParse(DtRcvTxt.Text, out dt) ? dt : (DateTime?)null;
            //q.SubmtBy = DateTime.TryParse(SbmtTxt.Text, out dt) ? dt : (DateTime?)null;
            //q.DtReqFx = DateTime.TryParse(DtReqFx.Text, out dt) ? dt : (DateTime?)null;
            RqAgy.SelectedItem.Text=q.ReqAgy;
            RnkReqAgy.SelectedItem.Text=q.RnkReq;
            LnamReqAgy.Text=q.LnamReq;
            LdTxtbx.Text=q.LwDpt;
            LrTxtbx.Text=q.LglReq;
            CmplntTxt.Text=q.Cmplnt;
            CmntsTxt.Text=q.Cmnt;
            CoDDL.SelectedItem.Text=q.CrtOrdr ;
            Cse.Text=q.Case_;
            LgTxt.Text=q.Log_;
            GrpDDL.SelectedItem.Text=q.Grp_;
            RnkRecReqDDL.SelectedItem.Text=q.RnkRec;
            LnamRecAgy.Text=q.LnamRec;
            FivDDL.SelectedItem.Text=q.Finv;
            OGtxt.Text=q.OG_;
        }
   
    }
}
ASKER CERTIFIED SOLUTION
Kaushal Arora
Technical Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros