Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8580905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:55:32+00:00 2026-06-11T20:55:32+00:00

Can i get some help please. I have a query as shown below. Right

  • 0

Can i get some help please. I have a query as shown below. Right now it shows both cheque and cash. But i want it to show only cash query. Yes, i believe i can edit it(now its vulnerable to SQL Injections)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace MyTestData
{
public partial class frmCollection : Form
{
    public frmCollection()
    {
        InitializeComponent();
    }


    private void dtpFrom_ValueChanged(object sender, EventArgs e)
    {

    }

    private void btnExtract_Click(object sender, EventArgs e)
    {

        SqlConnection objConn = new SqlConnection("MYCONNECTION STRING ETCETC");


        SqlCommand objCmd = new SqlCommand("SELECT CONVERT(char(10),PaidDate,3)
 AS PaidDate,InvoiceNo,PayerCode,CollectedFee,
( CASE ReceiptTypeID WHEN 'Cash' THEN 'CASH' WHEN 'Check' THEN 'CHEQUE' END ) 
AS ReceiptTypeID FROM InvoicePayment 
WHERE (PaidDate >= CONVERT(datetime, '" + dtpFrom.Text + "', 105)) AND (PaidDate <= CONVERT(datetime, '" + dtpTo.Text + "', 105))", objConn);

        SqlDataReader objReader;
        objReader = objCmd.ExecuteReader();

        System.IO.FileStream fs = new System.IO.FileStream("C:\\CMSExportedData\\Collection-" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt", System.IO.FileMode.Create);
        System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.Default);

        int count = 0;
        while (objReader.Read())
        {

            for (int i = 0; i < 5; i++)
            {
                if (!objReader.IsDBNull(i))
                {
                    string s;
                    s = objReader.GetDataTypeName(i);
                    //MessageBox.Show(s);
                    if (objReader.GetDataTypeName(i) == "char")
                    {
                        sw.Write(objReader.GetString(i));
                    }
                    else if (objReader.GetDataTypeName(i) == "money")

                    {
                        sw.Write(objReader.GetSqlMoney(i).ToString());
                    }
                    else if (objReader.GetDataTypeName(i) == "nvarchar")
                    {
                        sw.Write(objReader.GetString(i));
                    }
                    else if (objReader.GetDataTypeName(i) == "varchar")
                    {
                        sw.Write(objReader.GetString(i));
                    }

                }
                if (i < 4)
                {
                    sw.Write("\t");
                }

            }
            count = count + 1;
            sw.WriteLine();

        }
        sw.Flush();
        fs.Close();
        objReader.Close();
        objConn.Close();
        MessageBox.Show(count + " records exported successfully.");
        this.Close();

    }

    private void frmCollection_Load(object sender, EventArgs e)
    {

    }

    private void dtpFrom_ValueChanged_1(object sender, EventArgs e)
    {

    }
}

}

Edit: Here is the table structure:

enter image description here

Here is some sample data:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:55:33+00:00Added an answer on June 11, 2026 at 8:55 pm

    I only wish to see cash

    Then remove WHEN 'Check' THEN 'CHEQUE' from the CASE expression like so:

    SELECT 
      CONVERT(char(10),PaidDate,3) AS PaidDate,InvoiceNo,
      PayerCode, CollectedFee, 
      (CASE ReceiptTypeID 
         WHEN 'Cash'  THEN 'CASH'  
      END ) AS ReceiptTypeID 
    ...
    

    Update:

    SELECT 
      CONVERT(char(10), PaidDate,3) AS PaidDate,
      InvoiceNo, CollectedFee, upper(ReceiptTypeID) AS ReceiptTypeID 
    FROM @Invoices 
    WHERE (PaidDate >= CONVERT(datetime, '20010101', 105))
      AND (PaidDate <= CONVERT(datetime, '20120101', 105))
      AND ReceiptTypeID IS NOT NULL
      AND lower(ReceiptTypeID) <> 'cheque'
    

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with this please I can't get a handle on it.
Could I get some help creating this query please? Users book product video slots
I am curious if I can get some help with Open Graph since I
I'm trying to optimize this mysql query using EXPLAIN. Can somebody please help me
I need some help with my query. I have 2 tables: all: art|serie sootv:
I have a stored procedure for query some data. I want get this data
Please help me to structure mysql query I have 2 tables, #_ udjacomment AND
Ive just had some fantastic help from Sandeepan, thank you! Please can anyone see
Im new to programming and hopefully can get some guidance, I searched for clues
Is there a way in which I can get some information about the mounts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.