i have these two tables connected to each other
tblOrder
ID - int (P.K.)
DateTime - datetime
TotalPrice - money
StaffID - int
OrderTypeID - int
ReservationID - int (F.K.) can be null
Paid - bit
tblReservation
ID - int (P.K.)
DateTimeReservation - datetime
NumberOfPeople - int
DateTimeOfEvent - datetime
EventTypeID - int
Done - bit
CustomerID - int
StaffID - int
Cancelled - bit
Now in tblOrder reservationID can be null.. I did the following statement but still it is not working can u help pls?
public bool AddOrder(Order o)
{
try
{
conn.Open();
SqlCommand comm;
if (o.ReservationID == 0)
{
comm = new SqlCommand("INSERT INTO tblOrder VALUES ('" + o.DateTime.ToString("MM/dd/yyyy HH:mm:ss") + "','" + o.TotalPrice + "','" + o.StaffID + "','" + o.OrderTypeID + "','" + null + "','" + o.Paid + "')", conn);
}
else
{
comm = new SqlCommand("INSERT INTO tblOrder VALUES ('" + o.DateTime.ToString("MM/dd/yyyy HH:mm:ss") + "','" + o.TotalPrice + "','" + o.StaffID + "','" + o.OrderTypeID + "','" + o.ReservationID + "','" + o.Paid + "')", conn);
}
comm.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
return false;
}
finally
{
conn.Close();
}
}