{"id":161,"date":"2016-02-18T19:07:47","date_gmt":"2016-02-18T19:07:47","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=161"},"modified":"2022-02-17T06:24:14","modified_gmt":"2022-02-17T06:24:14","slug":"insert-or-replace","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/databases\/sqlite\/queries\/insert-or-replace","title":{"rendered":"INSERT OR REPLACE"},"content":{"rendered":"<p>\n\tINSERT new record or REPLACE existing record if the primary key&nbsp;already exists\n<\/p>\n<pre>\r\n<code>\r\n\tCommand1 = new System.Data.SQLite.SQLiteCommand(Connection1);\r\n\tCommand1.CommandText = @&quot;INSERT OR REPLACE INTO tblBookCards\r\n\t\t\t\t\t\t\t\t(CardId, CardPicture)\r\n\t\t\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t\t\t(@CardId, @CardPicture)&quot;;\r\n\tCommand1.Parameters.AddWithValue(&quot;@CardId&quot;, CardId);\r\n\r\n\tif (BookCardImage.Length &gt; 0)\r\n\t\tCommand1.Parameters.AddWithValue(&quot;@CardPicture&quot;, BookCardImage);\r\n\telse\r\n\t\tCommand1.Parameters.AddWithValue(&quot;@CardPicture&quot;, DBNull.Value);\r\n<\/code><\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>INSERT new record or REPLACE existing record if the primary key&nbsp;already exists Command1 = new System.Data.SQLite.SQLiteCommand(Connection1); Command1.CommandText = @&quot;INSERT OR REPLACE INTO tblBookCards (CardId, CardPicture) VALUES (@CardId, @CardPicture)&quot;; Command1.Parameters.AddWithValue(&quot;@CardId&quot;, CardId); if (BookCardImage.Length &gt; 0) Command1.Parameters.AddWithValue(&quot;@CardPicture&quot;, BookCardImage); else Command1.Parameters.AddWithValue(&quot;@CardPicture&quot;, DBNull.Value); &nbsp; &nbsp;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-161","post","type-post","status-publish","format-standard","hentry","category-queries"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/161\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}