0

I already found the MySQL query that I want to use

INSERT INTO tbl_time_in (studentID, studentDAY, studentDATE, studentTIME_IN, temp_schedule_ID)
SELECT *  
FROM (SELECT 'rupert', 'Tuesday', 'June 29, 2016' ,'23:20', '59') AS tmp
WHERE NOT EXISTS (SELECT studentID 
                  FROM tbl_time_in 
                  WHERE studentID = 'rupert' and studentDATE = 'June 29, 2016' and temp_schedule_ID = '59')

but I also want to know how could I implement this in C# correctly.

I tried to use ExecuteNonQuery and ExecuteReader but it always gives an empty result.

1
  • What do you want to return? Commented Jun 29, 2016 at 4:23

2 Answers 2

1

In MySQL database you can use the ON DUPLICATE KEY UPDATE function this will lessen using of sub query. Check this link for further references.

Sign up to request clarification or add additional context in comments.

Comments

0

well, you can implement this in if else statement, using a integer counter to check is the data exists or not, 1st fire the count statement and store the result in an integer, 2nd compare the the result with a 0 value - if result > 0 then the data exists in the database, else (it means result = 0) do insert Query

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.