插入数据前先检查数据是否存在,有则提示数据已存在,没有则插入当前表

解决方案 »

  1.   

    string sql="if not exists(select * from [" + tablename + "] where  ["+PKName+"]=@"+PKValue+")  begin\r\n  INSERT INTO [" + tablename + "](字段,字段.....)values(值,值....) \r\n end ";
      

  2.   

    string sql="if not exists(select * from [tablename ] where  [PKName]='"PKValue"')  begin\r\n  INSERT INTO [" + tablename + "](字段,字段.....)values(值,值....) \r\n end ";