im confused on how to do this as I am quite new to accessing sql server by c#. I want to query table quiz with conditions where time is in between startTime and EndTime. however, when i try to add the time parameter, it says I have a null reference exception.
DateTime date = DateTime.Now;
SqlConnection con = new SqlConnection("Data Source=.\\SQLSERVER;Initial Catalog=quizMaker;Integrated Security=True");
SqlCommand com;
subjects = "Subject-3";
con.Open();
SqlParameter time = new SqlParameter("@time", SqlDbType.DateTime);
time.Value = date;
com.Parameters.Add(time); //error pops up here
SqlParameter subjected = new SqlParameter("@subject", SqlDbType.VarChar, 20);
subjected.Value = subjects;
com = new SqlCommand("Select * from quiz where StartTime<=@time and EndTime>=@time and Subject_ID = @subject", con);
com.ExecuteNonQuery();
con.Close();