How do i display this record by now date
I just want to display daily gross amount on both dropdown and formview, that means if there is no sales that day the dropdown will be empty including the formview. So there is going to be a sales page where the sales are inserted into table, on Account balance page it will only display the gross profit of that day on form view and dropdown control.
using (SqlConnection con = new SqlConnection(constr))
{
//SqlCommand cmd4 = new SqlCommand("Update Customer_Order set OrderDate= @OrderDate, Posted_By = @Posted_By, Branch=@Branch, CustomerID= @CustomerID, Payment_Methode= @Payment_Methode, Product_Code =@Product_Code, Category = @Category, Brand = @Brand, Delivery_Manager =@Delivery_Manager, Quantity_By_Customer = @Quantity_By_Customer, Discount =@Discount, Unit_Price = @Unit_Price, Bank_Name = @Bank_Name, Delivery_Location= @Delivery_Location, Delivery_Date = @Delivery_Date, Total_Cost = @Total_Cost, Grand_Total = @Grand_Total WHERE Invoice_No= @Invoice_No", con9);
using (SqlCommand cmd = new SqlCommand("SELECT Gross, Date FROM SalesBalancing WHERE Gross = @Gross AND Date = @Date"))
{
cmd.Parameters.AddWithValue("@Gross", "Gross");
cmd.Parameters.AddWithValue("@Date", DateTime.Now);
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GetSum.DataSource = dt;
GetSum.DataBind();
}
}
}
}
i tried it this way and it worked, but i dont know if this method is the right way to apply. this method is ok?
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Gross FROM SalesBalancing WHERE Date='" + DateTime.Today + "'"))
{
//cmd.Parameters.AddWithValue("@Gross", "Gross");
cmd.Parameters.AddWithValue("@Date", DateTime.Now);
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GetSum.DataSource = dt;
GetSum.DataBind();
}
}
}