S
scota
I am new to ASP.NET, C#. I have the following code which will not
display the total Credits for all the records. It is printing "Total
Credits: 0" instead of adding the credits. What am I missing?
Credits is the 4th column in the datagrid and the 4th field in the SQL
view. Credits data type is float.
Thank you.
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection objConnection;
SqlCommand objCommand;
String strConn;
strConn =
ConfigurationManager.ConnectionStrings["web_CMEConnectionString"].ToString();
objConnection = new SqlConnection(strConn);
objConnection.Open();
string strSQL = "SELECT * FROM vw_PINTopic WHERE PIN = " +
txtPIN.Text.ToString() + " AND [DATE] between '" +
calStart.SelectedDate + "' and '" + calEnd.SelectedDate + "'";
Trace.Write(strSQL);
objCommand = new SqlCommand(strSQL, objConnection);
objCommand.CommandType = CommandType.Text;
SqlDataReader objReader = objCommand.ExecuteReader();
if (objReader.HasRows)
{
dgResults.DataSource = objReader;
dgResults.DataBind();
dgResults.Visible = true;
double sumTotal = 0;
using (objReader)
{
while (objReader.Read())
{
sumTotal += objReader.GetDouble(3);
}
lblPIN.Text = "Total Credits: " + sumTotal;
}
}
else
{
dgResults.Visible = false;
lblPIN.Text = txtPIN.Text + " has no courses within this
timeframe.";
}
objReader.Close();
objConnection.Close();
}
display the total Credits for all the records. It is printing "Total
Credits: 0" instead of adding the credits. What am I missing?
Credits is the 4th column in the datagrid and the 4th field in the SQL
view. Credits data type is float.
Thank you.
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection objConnection;
SqlCommand objCommand;
String strConn;
strConn =
ConfigurationManager.ConnectionStrings["web_CMEConnectionString"].ToString();
objConnection = new SqlConnection(strConn);
objConnection.Open();
string strSQL = "SELECT * FROM vw_PINTopic WHERE PIN = " +
txtPIN.Text.ToString() + " AND [DATE] between '" +
calStart.SelectedDate + "' and '" + calEnd.SelectedDate + "'";
Trace.Write(strSQL);
objCommand = new SqlCommand(strSQL, objConnection);
objCommand.CommandType = CommandType.Text;
SqlDataReader objReader = objCommand.ExecuteReader();
if (objReader.HasRows)
{
dgResults.DataSource = objReader;
dgResults.DataBind();
dgResults.Visible = true;
double sumTotal = 0;
using (objReader)
{
while (objReader.Read())
{
sumTotal += objReader.GetDouble(3);
}
lblPIN.Text = "Total Credits: " + sumTotal;
}
}
else
{
dgResults.Visible = false;
lblPIN.Text = txtPIN.Text + " has no courses within this
timeframe.";
}
objReader.Close();
objConnection.Close();
}