By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

select data from data grid view between two dates

P: 1
I'm trying to select data between tow dates(values given by date time pickers) I try more. but can't go forward. here is my code :
Expand|Select|Wrap|Line Numbers
  1. Try
  2.             If (con.State = ConnectionState.Closed) Then
  3.                 con.Open()
  4.             End If
  5.             cmd = New MySqlCommand("SELECT * FROM mcs.daily_income where date_received between @d1 and @d2", con)
  6.             cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "JoiningDate").Value = dtpstart.Value.Date
  7.             cmd.Parameters.Add("@d2", SqlDbType.DateTime, 30, "JoiningDate").Value = dtpend.Value.Date
  8.             da = New MySqlDataAdapter(cmd)
  9.             ds = New DataSet()
  10.             da.Fill(ds, "Staff")
  11.             dgvreciept.DataSource = ds.Tables("Staff").DefaultView
  12.             ds.Clear()
  13.             da.Dispose()
  14.             con.Close()
  15.         Catch ex As Exception
  16.             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  17.         End Try
  18.         Dim ii As Integer
  19.         Dim total As Decimal
  20.         For ii = 0 To dgvreciept.Rows.Count - 1
  21.             total = total + Val(dgvreciept.Item("Amount", ii).Value.ToString) ' or you can use Cint
  22.         Next
  23.         lbltdtotal.Text = total
  24.  
my data grid view item's name : dgvreciept
date time pickers names :
1- dtpstart
2- dtpend

After selecting data I want to compute sum of amount field.
when I run this that give me error:
"Invalid cast from 'date time' to 'single' "

Please be kind to help my prob :)
Jan 23 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.