0

これが私がやろうとしていることです、私はLinQデータコンテキストを使用して新しいレコードをデータベースに挿入しています.何らかの理由で、私のlinqはこのエラーを表示しています "LinqDataSource 'AirAsiaDC' has no values to insert. Check that the 'values' dictionary contains.値。」変な部分ですが、前に挿入しようとしたレコードを確認すると、そこにあります。ここで何が間違っていますか?

ちなみに、ここに私のコードがあります:

protected void DetailsView1_ItemCommand(object sender, 
                                        DetailsViewCommandEventArgs e)
{
    AirAsiaDCDataContext Linq = new AirAsiaDCDataContext();

    try
    {
        if (e.CommandName == "Edit")
        {
            TextBox tbname = (TextBox)DetailsView1.FindControl("DeptName");
            department dpt;

            if ((tbname.Text != null) && (tbname.Text != ""))
            {
                dpt = Linq.departments.Single(d => d.departmentcode == code);
                dpt.departmentname = tbname.Text;
                dpt.updateby = "hendra";
                dpt.lastupdate = DateTime.Now;
                Linq.SubmitChanges();
                Response.Redirect("Department.aspx");
            }
            else
            {
                divError.Visible = true;
                lblError.Text = "Department name can not be empty";
            }
        }
        else if (e.CommandName == "Insert")
        {
            TextBox tbcode = (TextBox)DetailsView1.FindControl("DeptCode");
            TextBox tbname = (TextBox)DetailsView1.FindControl("DeptName");
            department dpt = new department();

            if (((tbcode.Text != null) && (tbcode.Text != "")) 
             && ((tbname.Text != null) && (tbname.Text != "")))
            {
                dpt.departmentcode = tbcode.Text;
                dpt.departmentname = tbname.Text;
                dpt.createby = "hendra";
                dpt.createdate = DateTime.Now;
                dpt.updateby = "hendra";
                dpt.lastupdate = DateTime.Now;
                Linq.departments.InsertOnSubmit(dpt);
                Linq.SubmitChanges();
            }
            else if ((tbcode.Text == null) || (tbcode.Text == ""))
            {
                divError.Visible = true;
                lblError.Text = "Department code can not be empty";
            }
            else if ((tbname.Text == null) || (tbname.Text == ""))
            {
                divError.Visible = true;
                lblError.Text = "Department name can not be empty";
            }
        }
    }
    catch (Exception ex)
    {
        divError.Visible = true;
        lblError.Text = ex.Message.ToString();
    }
}

try と catch を使用しようとしても何も得られず、linq はそのエラーを表示し続け、エラー画面にスローします。

4

0 に答える 0