I have created a table tblAttendence
in the database that has 2 columns: Date
(datetime
) and RegNo
(int
). I have to insert the current date & time and a registration number from a label in the form.
C# code:
private void btnMarkAtt_Click(object sender, EventArgs e)
{
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
sqlCon.Open();
SqlCommand sqlCmd = new SqlCommand("MarkAtt", sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@Date", DateTime.Now);
sqlCmd.Parameters.AddWithValue("@RegNo", int.Parse(lblRegNo.Text));
sqlCmd.ExecuteNonQuery();
MessageBox.Show("Attendance marked successfully!");
}
}
Stored procedure MarkAtt
:
ALTER PROCEDURE [dbo].[MarkAtt]
@Date DATETIME,
@RegNo INT
AS
INSERT INTO tblAttendence(Date, RegNo)
VALUES (@Date, @RegNo)
There is no error shown in the code. The debugging doesn't stop to show an error. When I press the button, just nothing happens (neither the data is inserted, nor the message box is shown).
I can't seem to find out what is going on. The connection string is correct (I have used it in the same form and it works). Is there something wrong with the connection? Or the stored procedure? Or anything else that I am missing?