Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Add/Delete Record

Add/Delete Record

Scheduled Pinned Locked Moved ASP.NET
databasetutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shapper
    wrote on last edited by
    #1

    Hello, I have a string with an email address. I want to look at an Access database to see if there is any record with that email. If there is a record I want to delete it. If there is no record I want to add a new one with that email address as value in field Email. I allready have the connection defined in the web.config file. Could someone tell me how to do this? Thanks, Miguel

    T Y 2 Replies Last reply
    0
    • S shapper

      Hello, I have a string with an email address. I want to look at an Access database to see if there is any record with that email. If there is a record I want to delete it. If there is no record I want to add a new one with that email address as value in field Email. I allready have the connection defined in the web.config file. Could someone tell me how to do this? Thanks, Miguel

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      SQL create proc insertEmail (@email varchar(50)) as if exsist( select * from dbo.yourTable where where email = @email ) delete dbo.yourTable where where email = @email else begin insert into dbo.yourTable (email) select @email end C# SqlConnection conn = new SqlConnection(); conn.ConnectionString = "YourString"; SqlCommand cmd1 = new SqlCommand(); cmd1.CommandText = "insertEmail"; cmd1.Connection = conn; cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.Add(new SqlParameter("@email", stringEmail)) conn.Open(); cmd1.ExecuteNonQuery(); conn.Dispose;


      how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

      S 1 Reply Last reply
      0
      • T ToddHileHoffer

        SQL create proc insertEmail (@email varchar(50)) as if exsist( select * from dbo.yourTable where where email = @email ) delete dbo.yourTable where where email = @email else begin insert into dbo.yourTable (email) select @email end C# SqlConnection conn = new SqlConnection(); conn.ConnectionString = "YourString"; SqlCommand cmd1 = new SqlCommand(); cmd1.CommandText = "insertEmail"; cmd1.Connection = conn; cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.Add(new SqlParameter("@email", stringEmail)) conn.Open(); cmd1.ExecuteNonQuery(); conn.Dispose;


        how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

        S Offline
        S Offline
        shapper
        wrote on last edited by
        #3

        Hello, Is it possible to create this using the SQL code in a QueryString in Asp.Net? It is just I am not used to use SQL procedures and I am not even sure if I can use them in an Access Database. Thanks, Miguel

        E 1 Reply Last reply
        0
        • S shapper

          Hello, I have a string with an email address. I want to look at an Access database to see if there is any record with that email. If there is a record I want to delete it. If there is no record I want to add a new one with that email address as value in field Email. I allready have the connection defined in the web.config file. Could someone tell me how to do this? Thanks, Miguel

          Y Offline
          Y Offline
          YeHtut
          wrote on last edited by
          #4

          I would to suggest... 1) Take Count(*) From your table. 2) If record is greater than 0 then do delete action. 3) Finally U take insert action. Other way, 1) Never checking the record and take delete action. 2) Finally insert action. Anyway U can do as u like. Cheer. :)

          1 Reply Last reply
          0
          • S shapper

            Hello, Is it possible to create this using the SQL code in a QueryString in Asp.Net? It is just I am not used to use SQL procedures and I am not even sure if I can use them in an Access Database. Thanks, Miguel

            E Offline
            E Offline
            eggsovereasy
            wrote on last edited by
            #5

            You can use put a raw sql statement in a string for ADO.NET, but I would highly recommend against putting it in the query string, that would make it viewable to the entire world (and editable). The results would likely be catestrophic.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups