I have two tables, one called DogContract and one called WeeklyBooking. They both share two columns, called ContractLength and DogID.
I am currently programming a function for the user to use the GUI to input a new WeeklyBooking object into the table. I am attempting to retrieve the ContractLength value. I have a textbox where the user inputs the DogID and in theory my code is to take the ContractLength Value from DogContract and then assign it as the ContractLength for the weeklybooking object. I have a function in my WeeklyBookingDataAccess class to do this:
public int getContractLength(string dogID, WeeklyBooking week)
{
SqlCommand getCLength = new SqlCommand("SELECT ContractLength FROM WeeklyBooking WHERE DogID =" + dogID);
try
{
db.Conn.Open();
week.contractLength = (int)db.Cmd.ExecuteScalar();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return week.contractLength;
}
This method is called in the function I'm using to create the WeeklyBooking object. The problem is, when I check the table data the ContractLength Value is always set to zero. Has anybody any ideas as to fix this problem? -Thanks