Hi,
I am getting the error as
"use of unassigned local variable 'k1'" whenever i am compiling my project. My Code is :
public DataSet wsGenerateBill(string OrderID)
{
string total1 = string.Empty;
float FinalTotal = 0;
int k1, k2 = 0;
try
{
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("SELECT OrderDetails.FoodID, OrderDetails.Qty, OrderDetails.Price, OrderDetails.Qty * OrderDetails.Price AS Total From OrderDetails Where (OrderID = '" + OrderID + "')", con);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(sdr);
con.Close();
int m = od1.UpdateTotalAmtOfFood(OrderID);
if (dt.Rows.Count == 0)
{
return null;
}
else
{
for( int i =0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
string foodid = dr["FoodID"].ToString();
string quantity = dr["Qty"].ToString();
string price = dr["Price"].ToString();
string total = dr["Total"].ToString();
int quantity1 = int.Parse(quantity);
int price1 = int.Parse(price);
float billtotal = float.Parse(total);
FinalTotal = FinalTotal + billtotal;
}
object outletid = orders.getOutletIDByOrderID(OrderID);
string outletid1 = (string)outletid;
object exist = bill.getBillIDByOrderID(OrderID);
if (exist == null)
k1 = bill.CreateBill(OrderID, outletid1, FinalTotal,'0','0');
if (k1 > 0)
k2 = bill.UpdateGrandTotalOfBill(OrderID);
SqlCommand cmd1 = new SqlCommand("SELECT Bill.BillID, Bill.OutletID, Bill.OrderID, [Order].CustomerID, Customer.Name AS CustomerName, [Order].DestinationPlace, [Order].VehicleNo, [Order].SeatNo, [Order].PaymentMode, [Order].OrderDate, [Order].DeliveryTime, [Order].DeliveryDate, Outlet.Name AS OutletName, Outlet.City AS OutletCity, OrderDetails.FoodID, Food.Name AS FoodName, OrderDetails.Qty, OrderDetails.Price, OrderDetails.Total AS FoodTotal, Bill.OrderTotalAmt, Bill.TaxAmt, Bill.GrandTotal FROM Bill INNER JOIN [Order] ON Bill.OrderID = [Order].OrderID INNER JOIN Customer ON [Order].CustomerID = Customer.CustomerID INNER JOIN Outlet ON Bill.OutletID = Outlet.OutletID INNER JOIN OrderDetails ON [Order].OrderID = OrderDetails.OrderID INNER JOIN Food ON OrderDetails.FoodID = Food.FoodID WHERE (Bill.OrderID = '" + OrderID + "')", con);
con.Open();
SqlDataReader sdr1 = cmd1.ExecuteReader();
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Load(sdr1);
con.Close();
if (dt1.Rows.Count == 0)
{
DataTable table1 = new DataTable("Bill");
table1.Columns.Add("Result");
table1.Rows.Add("Null");
ds1.Tables.Add(table1);
return ds1;
}
else
{
ds1.Tables.Add(dt1);
return ds1;
}
}
}
catch (Exception)
{
return null;
}
}
Please tell me where i am going wrong. I am new in this field.
Thanks in advance...