1

I am tried to get count of a particular item from mysql table using c#.but i got nothing

My code

string Batch = textBox8.Text;
string batchnumber = ("SELECT COUNT [Batch_No] FROM Orders where Batch_No='" + Batch + "'");

orders is my table and batch_no is the column and i want to get the count of particular batch number in the table.How can i do this?

Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
Unnikrishnan.S
  • 185
  • 2
  • 17
  • "SELECT COUNT (*) FROM Orders where Batch_No='" + Batch + "'" – Kami Jan 05 '16 at 13:37
  • @Kami:I need to get the count of Batch_no – Unnikrishnan.S Jan 05 '16 at 13:41
  • Then use SUM function on the Batch_No column. There is a post that might help you. http://stackoverflow.com/questions/4586040/mysql-sum-elements-of-a-column – Kami Jan 05 '16 at 13:46
  • Count only gives you a count of records whereas SUM will give you a sum of the selected column (numerical of course). – Kami Jan 05 '16 at 13:53

1 Answers1

0

Change COUNT [Batch_No] to COUNT(Batch_No). It will work.

Try this:

string Batch = textBox8.Text;
string batchnumber = ("SELECT COUNT(Batch_No) FROM Orders WHERE Batch_No='" + Batch + "'");
Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83