Add/Delete Record
-
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
-
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
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
-
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
-
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
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. :)
-
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
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.