0

I'm trying to save a txt file with Contact numbers of people who have paid but i get an error saying there is an error with

"OleDbDataReader dbReader = cmd.ExecuteReader()"

saying "Data type mismatch in criteria expression". I think its the SELECT statement causing the problem, in access [Paid] is a Yes/No data type, What is the correct way of Selecting the data

 try
        {
            string connString = (@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|DB.mdb");
            OleDbConnection conn = new OleDbConnection(connString);
            conn.Open();
            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = @"SELECT [CellNumber] FROM [Users] WHERE [Paid] = '1'";
            OleDbDataReader dbReader = cmd.ExecuteReader();

            StreamWriter sw = new StreamWriter("E:/Contacts.txt");
            while (dbReader.Read())
            {
                sw.WriteLine(cmd.ExecuteScalar().ToString());
            }
            sw.Close();
            dbReader.Close();
            conn.Close();

        }
        catch (OleDbException abc) 
        {
            errorLabel.Text = abc.ToString();
        }
RogueSpear00
  • 619
  • 2
  • 9
  • 24

1 Answers1

0

The [Paid] column is a non-string type, so try removing the single quotes:

cmd.CommandText = @"SELECT [CellNumber] FROM [Users] WHERE [Paid] = 1";

As always, use parameters where appropriate.

LarsTech
  • 80,625
  • 14
  • 153
  • 225