I am a new C# and ASP.NET developer. I am developing a simple intranet booking management system for my company. I want the system to check if the user has a booking before in the event or not.
I have the following database design:
Users Table: UserID, Name
Events Table: ID, Title, Description, Location, NumberOfSeats, StartDateTime, EndDateTime, IsActive
Booking Table: BookingID, EventID, UserID
What I did so far is checking the UserID (when the user clicks on Booking button) if it is in the Users Table or not. If not, he will be added automatically to the database. Now I want to check if he has a booking in that event or not by checking BookingDetails table but I don’t know how to do that?
Could you please help me in designing this condition?
Here’s my method for checking the username:
protected void checkUserID(string userID) {
int eventID = Convert.ToInt32(HiddenField1.Value);
string NetworkID = userID;
string Name = Service.(".......");
string BadgeNo = Service("ffffff");
string DepartmentCode = Service("ffffff");
string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=RegistrationSysDB;Integrated Security=True;";
//if the user is not in the system database, add him
if (Security.isExisted(userID) == false)
{
//string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=RegistrationSysDB;Integrated Security=True;";
string insertCommand = "INSERT INTO Users (NetworkID, Name, BadgeNo, DepartmentCode) values (@NetworkID, @Name, @BadgeNo, @DepartmentCode)";
using(SqlConnection conn = new SqlConnection(connString))
{
//Open DB Connection
conn.Open();
using(SqlCommand cmd = new SqlCommand(insertCommand, conn))
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@NetworkID", NetworkID);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@BadgeNo", BadgeNo);
cmd.Parameters.AddWithValue("@DepartmentCode", DepartmentCode);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
}
You haven’t set the parameters on the SELECT command, here is the revised code below.