Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to sum all values in column "GlassesPrice" and show it in message box.
double income = 0;
            DataTable dt = new DataTable();
            string date = toolStripComboBox3.Text +"/"+ toolStripComboBox2.Text +"/"+ toolStripComboBox1.Text;
            string strconn = @"Data Source=C:\DB\opticsinfo.sdf";
            SqlCeConnection conn = new SqlCeConnection(strconn);
            conn.Open();
            SqlCeCommand cmd = new SqlCeCommand("select SUM(GlassesPrice) as income from EyeGlasses where CheckinDate=" + date + ";", conn);
            SqlCeDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                income = Convert.ToDouble(dr[0]);
            }
            conn.Close();
            MessageBox.Show(income.ToString());
C#



but i have exception in the underline line
"
Data conversion failed. [ OLE DB status value (if known) = 2 ]
"
what is the problem??
Posted

1 solution

can you please check the sqlquery ,whether you are able to get the data based on above query in sqlserver

If query is correct can you change the query as below and run and see what result you are getting

C#
SqlCeCommand cmd = new SqlCeCommand("select SUM(GlassesPrice) as income from EyeGlasses where CheckinDate='" + date +"'", conn);


If you have any issue ...please ask
 
Share this answer
 
Comments
Member 9557321 5-Dec-13 13:15pm    
Thanx bro there is single colon missed
5 hours trying to solve it, although it is not first time to do it.
thanks again :)
keerth516 7-Dec-13 22:51pm    
your welcome ...keep smiling
Member 14058289 21-Sep-19 23:09pm    
how to sum two table field and show dataGridView one
columns with out inner join

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900