public int add_field(string strFile_Code,string strFile_Name)
        {
            var newField = new TB_Fild
            {
                newField.File_Code = strFile_Code,
                newField.File_Name= strFile_Name                
                
            };            
            dc.TB_Filds.InsertOnSubmit(newField);//错误行
            dc.SubmitChanges();
            return 0;
        }
想往表里插入一条新记录
错误信息:
Can't perform Create, Update or Delete operations on 'Table(TB_Fild)' because it has no primary key.

解决方案 »

  1.   

    你这样试试,应该没有问题的public int add_field(string strFile_Code,string strFile_Name) 
            { 
                //TB_Fild为table的名称
                TB_Fild newField = new TB_Fild();
                    newField.File_Code = strFile_Code, 
                    newField.File_Name= strFile_Name                
                             
                dc.TB_Filds.InsertOnSubmit(newField);//错误行 
                dc.SubmitChanges(); 
                return 0; 
            }