i have this code on button click when there is no record between selected dates therfore nothing is to sum as below i shown i got error "Specified cast is not valid." how i can do that if there is no record show a messag
private void button2_Click(object sender, EventArgs e)
{
label4.Text = "";
try
{
my.Open();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("Select * from add_investor Where date>='" + dateTimePicker1.Value + "'AND date<='" + dateTimePicker2.Value + "' ", my);
da.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
my.Close();
using (SqlCommand cmd = new SqlCommand("SELECT SUM(investor_amount) FROM add_investor WHERE date>='" + dateTimePicker1.Value + "'AND date<='" + dateTimePicker2.Value + "' ", my))
{
my.Open();
int result = (int)cmd.ExecuteScalar();----------------------------------------error
label4.Text = result.ToString();
my.Close();
}
}
catch
{
throw;
}
Loading
VulpesPosted Oct 2, 2013, 2:16 PM
ta muPosted Oct 2, 2013, 1:04 PM
now how i can manage it
thanks for reply
VulpesPosted Oct 2, 2013, 9:31 AM
ta muPosted Oct 2, 2013, 9:05 AM
VulpesPosted Oct 2, 2013, 8:38 AM
If you're summing investor_amounts, I'd have thought that double or decimal would be more likely.
ta muPosted Oct 2, 2013, 8:27 AM
result = (int)temp; Specified cast is not valid.
result value is zero
VulpesPosted Oct 2, 2013, 8:17 AM