TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ta mu
NA
201
82.1k
invalid cast
Oct 2 2013 8:04 AM
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;
}
Reply
Answers (
7
)
how to convert a code of C# form to C# wpf
Copy text(including formats) frm word doc into excel cell