我在弄清楚如何做一些看起来很简单的事情时遇到了一些麻烦,但是在提交更改时需要一些帮助来确定我哪里出错了。此 Windows 窗体的基本前提是查询数据库以获取有关窗体加载的特定信息,然后将其加载以进行任何需要进行的更改。
它加载得很好,我仔细检查以确保有一个主键(它是),但由于某种原因它不会保存。tkts.Log = Console.Out; 单击保存按钮时甚至不显示任何内容。我是一名初学者程序员,正在尝试 Linq to SQL,所以如果有什么问题,请提供指点。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TicketLogger;
namespace TicketLogger
{
public partial class TicketInfo : Form
{
ITDataClassesDataContext tkts = new ITDataClassesDataContext();
private Int32 ticket_id = 0;
public TicketInfo(Int32 TicketID = 0)
{
InitializeComponent();
//Set local TicketID variable for use on load
ticket_id = TicketID;
}
private void tBL_TICKET_HDRBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
//Save the new ticket to the database
//I think the object Tickets contains the changes, not tkts, but how to access?
try
{
tkts.Log = Console.Out;
tkts.SubmitChanges();
tkts.Log.Close();
}
catch (Exception m)
{
MessageBox.Show(m.ToString());
}
}
private void TicketInfo_Load(object sender, EventArgs e)
{
tkts.Log = Console.Out;
//Get the ticket ID and retrieve information
var Ticket = from objTkts in tkts.TBL_TICKET_HDRs
where objTkts.TICKET_ID == ticket_id
select objTkts;
this.tBL_TICKET_HDRBindingSource.DataSource = Ticket;
tkts.Log.Close();
}
}
}