• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

sql statement for c# mysql

I try to put sql state ment  in c# but it not work this sql statement I test with phpMyAdmin it work how can i solve the problem

SELECT membernameH, SUM(
CASE WHEN htype = 'pin'
THEN amount
ELSE 0
END ) AS pin, SUM(
CASE WHEN htype = 'pfi'
THEN amount
ELSE 0
END ) AS pfi, SUM(
CASE WHEN htype = 'ppr'
THEN amount
ELSE 0
END ) AS ppr
FROM hpay
GROUP BY membernameH

sql.JPG
0
teera
Asked:
teera
  • 2
  • 2
2 Solutions
 
teeraAuthor Commented:
Pleser see error in picture
sql2.JPG
0
 
Ashish PatelCommented:
>>>>How can i solve the problem?

Paste the c# code here so that we can look at what you are doing to this statement.
0
 
teeraAuthor Commented:
I am new foe c# I just use datagride
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void CopyClick(object sender, EventArgs e)
        {
            textBox2.Text = textBox1.Text;
        }
 
        private void villageDataSetBindingSource_CurrentChanged(object sender, EventArgs e)
        {
 
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'villageDataSet.balanceborow' table. You can move, or remove it, as needed.
            this.balanceborowTableAdapter.Fill(this.villageDataSet.balanceborow);
 
        }
 
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
 
        }
    }
}

Open in new window

0
 
Ashish PatelCommented:
Try writting the query in one line in the DataGrid, as you query looks good.

SELECT membernameH, SUM(CASE WHEN htype = 'pin' THEN amount ELSE 0 END) AS pin, SUM(CASE WHEN htype = 'pfi' THEN amount ELSE 0 END ) AS pfi, SUM(CASE WHEN htype = 'ppr' THEN amount ELSE 0  END ) AS ppr FROM hpay GROUP BY membernameH
0
 
gnoonCommented:
Try to use END CASE instead of END, for MySQL. http://dev.mysql.com/doc/refman/5.0/en/case-statement.html.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now