1

I am using Telerik's Radgridview. I currently have it populated with data from a test database and I do this by using a linq query when the window loads. I have two extra empty columns for users to enter in data, and what I want is to have any data entered into those columns be saved back to the database when the window is closed. That way the linq query will still work when I load the application back up again. I'm not entirely sure how to do this or what to put in my Window_Closing event. I've searched nearly every web article and thread on this and none of them have helped me with my particular issue. Specifically I am trying to update the DeductionInfo Table. This is my Window_Loaded event where I have my linq query that loads the data:

private void Window_Loaded(object sender, RoutedEventArgs e)
    {

        //Loads queries from each of the designated data tables in BSI_Test
        var customerQuery =
            (from customer in testEntity.Customers
             from deduction in testEntity.DeductionInfoes.DefaultIfEmpty()
             join job in testEntity.Jobs
             on customer.CID equals job.CID
             join claim in testEntity.Claims
             on job.JID equals claim.JID
             select new DataProperties
             {
                 Customer_Name = customer.CName,
                 Job_Name = job.JName,
                 Claim_No = claim.CLNumber,
                 Check_No = deduction.checkNo,
                 Check_Date = deduction.checkDate
             })
            .OrderBy(c => c.Customer_Name);

        //Populates the Telerik data grid with data.
        gridView.ItemsSource = customerQuery.ToList();
    }

This is what I tried in my Window_Closing event which didn't seem to work, and I was wondering if anyone could help me understand how to do this:

DataTable ds = new DataTable();
public void Window_Closing(object sender, CancelEventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source = databaseserver; Database = database; User ID = sampleUsername; Password = SamplePassword; Integrated Security = False;");
        con.Open();
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM DeductionInfo", con);
        adapter.Fill(ds);
        DataTable dt = ds.Tables[0];
        gridView.ItemsSource = dt;
        con.Close();
    }    

The DeductionInfo table is null by the way, since this data will be used to fill it up.

GamerTalks
  • 63
  • 9

0 Answers0