当前位置:编程学习 > C#/ASP.NET >>

ACCESS实施参照完整性后不能插入记录

<img src="www.dm007.net/1.gif"/>
如图,用程序插入时提示出错,去掉参照完整性后就可以插入。数据表里没有数据。
程序如下

        const string SQL_ORDERTABLE= "INSERT INTO ORDERTABLE (OrderSSN,UserID,TotalPrice,TotalQuantity,Message) VALUES (@OrderSSN,@UserID,@TotalPrice,@TotalQuantity,@Message)";
        const string  SQL_ORDERLIST= "INSERT INTO ORDERLIST (OrderSSN,ProductID,ProductSSN,Product,Quantity,DealPrice) VALUES (@OrderSSN,@ProductID,@ProductSSN,@Product,@Quantity,@DealPrice)";

........

                    using (OleDbTransaction trans = conn.BeginTransaction())
                    {
                        OleDbParameter[] sp=new OleDbParameter[]{new OleDbParameter("@OrderSSN",orderssn),new OleDbParameter("@ProductID",OleDbType.Integer),new OleDbParameter("@ProductSSN",OleDbType.Char,255),new OleDbParameter("@Product",OleDbType.Char,255),new OleDbParameter("@Quantity",OleDbType.Integer),new OleDbParameter("@DealPrice",OleDbType.Double)};
                        //try
                        //{
                        Database.ExecuteNonQuery(trans, CommandType.Text, SQL_ORDERTABLE, new OleDbParameter("@OrderSSN",orderssn),new OleDbParameter("@UserID",userid),new OleDbParameter("@TotalPrice",totalprice),new OleDbParameter("@TotalQuantity",quantity),new OleDbParameter("@Message",message));
                            foreach(CarModel cm in cml)
                            {
                                Database.ExecuteNonQuery(CommandType.Text, string.Format(SQL_PAYPRODUCT,cm.Quantity,cm.ProductID));
                                sp[1].Value = cm.ProductID;
                                sp[2].Value = cm.ProductSSN;
                                sp[3].Value = cm.Product;
                                sp[4].Value = cm.Quantity;
                                sp[5].Value = cm.DealPrice;                                Database.ExecuteNonQuery(CommandType.Text,SQL_ORDERLIST,sp);
}
........
哪位大哥知道,救我~~~ --------------------编程问答-------------------- 参照完整性不包括插入,要提供外键才能插入。
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,