You can set the column name by giving it an alias within the query:
... ABS(...) As YourColumnName ...
Rather than converting your
datetime
column to a string, test whether it is greater than or equal to the selected date, and less than one day after the selected date.
S1_DateTime >= @SelectedDate And S1_DateTime < DateAdd(day, 1, @SelectedDate)
Wrap your
SqlCommand
and
SqlConnection
objects in
using
statements.
And use parameterized queries to avoid
SQL Injection[
^].
using (SqlConnection con = new SqlConnection("..."))
using (SqlCommand cmd = new SqlCommand(" select S1_DateTime, S1_Weight, S2_Weight, AdjustmentWeight, ABS(convert(float, S1_Weight) - convert(float, S2_Weight) - convert(float, AdjustmentWeight)) As YourColumnName from dbo_OrderLines1 where S1_DateTime >= @SelectedDate And S1_DateTime < DateAdd(day, 1, @SelectedDate)", con))
{
cmd.Parameters.AddWithValue("@SelectedDate", Calendar1.SelectedDate);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Label1.Text ="number of rows = "+ dt.Rows.Count.ToString();
TextBox1.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
GridView1.Visible = true;
GridView1.DataSource = dt;
GridView1.DataBind();
}