using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.OleDb;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

public partial class Form1 : Form

{

private OleDbConnection connection = new OleDbConnection();

public Form1()

{

InitializeComponent();

connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Adish Jain\workspace\Soft\Db1.accdb;

Persist Security Info=False;";

}

private void Form1_Load(object sender, EventArgs e)

{

try

{

connection.Open();

label1.Text = "Connected";

connection.Close();

}

catch (Exception ex)

{

MessageBox.Show("Oops!");

}

}

private void bLogin_Click(object sender, EventArgs e)

{

connection.Open();

OleDbCommand command = new OleDbCommand();

command.Connection = connection;

command.CommandText = "select * from Table1 where Quantity='" + tbUser.Text + "' AND Price for 1='" + tbPass.Text + "'";

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

}

MessageBox.Show("{0} ");

connection.Close();

}

}

}
2 Spice ups

HI

– command.CommandText = “select * from Table1 where Quantity='” + tbUser.Text + “’ AND Price for 1='” + tbPass.Text + “'”; –

look at your select statement… where you have: AND Price for 1 =

that makes no sense, what is the reason you have the word ‘for’ in the statement?

2 Spice ups

If "Price for 1" is the column name (with spaces), than you need to put it in brackets [Price for 1]. Otherwise the column may be named wrong.

6 Spice ups

Thanks a ton… silly mistake and I’ve been scratching my head for a while now.
Thanks again sir.!!

Good catch Craig, It being the actual field name hadn’t crossed my mind! duh