手动ID代码中的问题

时间:2011-04-27 02:46:39

标签: c#

我的自动ID已经在运行。但是,我尝试了手动ID代码并在我的数据库中插入值。我的问题是我如何获得手册ID的值。是的,这很简单,但不是只读。

请检查我的代码:

删除 - 工作正常!

CMSInsurance oInsuranceDelete = new CMSInsurance();
                            Insurance oInsurance = new Insurance();

                            List<InsuranceLabel> lstName = oInsuranceDelete.RetrieveInsuranceList();
                            foreach (InsuranceLabel item in lstName)
                            {
                                var code = e.CommandArgument;
                                if (item.InsuranceCode.ID == code.ToString())
                                {
                                    oInsurance.InsuranceCode = item.InsuranceCode; //proper getting the value of Insurance Code instead of txtCode.text or  e.CommandArgument
                                    oInsuranceDelete.DeleteInsurance(oInsurance);
                                    bind();
                                }
                            }

插入自动ID代码 - 正常工作!

            oInsurance.Name = txtName.text // for string

            CMSInsurance oCMSInsurance = new CMSnsurance();
            oCMSInsurance.CreateInsurance(oInsurance);

插入手动识别码 - 不工作..

    //Get the Manual value of Insurance Code
    //For Insert a New Insurance
    CMSInsurance oCMSInsuranceManual= new CMSInsurance ();
    List<InsuranceLabel> lstList = oCMSInsuranceManual.RetrieveInsuranceList();
    foreach (InsuranceLabel item in lstList)
    {
        if (item.InsuranceCode.ID != Session["AutoCode"])
        {
        oInsurance.InsuranceCode = item.InsuranceCode; // I can't insert a string like txtCode.. is there anyway to solve this issue? 
        }
    }

谢谢!

1 个答案:

答案 0 :(得分:0)

与tSQL一样,SQL Anywhere不会“通常”允许插入标识字段:

  

SQL Server不允许INSERT进入   身份列除非   identity_insert选项设置为on

您可以在Sybase SQL Anywhere User's Guide

上找到有关SQL的更多信息