Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code is :
C#
int a = Convert.ToInt32(textBox1.Text);
            int b = Convert.ToInt32(textBox2.Text);
            try
            {
                //String typ = "1BHK";
                string str = "select propno,owner,address,phoneno,price,status,dimension,type from property where price between '" + a + "' and '" + b + "'";
                OleDbDataAdapter DAap = new OleDbDataAdapter(str, connString);
                DataSet DS = new DataSet();
                DAap.Fill(DS, "Property");
                DataTable DT = DS.Tables[0];
                dataGridView1.DataSource = DT;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Real Estate...       ", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }

it showing error as datatype missmatch in criteria expression in database price is a number type.
Posted
Updated 5-Oct-13 2:57am
v3

Shouldn't it be like this?

string str = "select propno,owner,address,phoneno,price,status,dimension,type from property where price between " + a + " and " + b;


P.S.: It's recommended to use Store Procedures instead of forming c# string queries. They are exposed to SQL Injection.
 
Share this answer
 
Comments
Raghavendra M 5-Oct-13 8:57am    
i am using MSAccess database
Raghavendra M 5-Oct-13 8:59am    
It is showing error as ;expected .
Try this,
//Make sure both have numeric value
string a = Convert.ToString(textBox1.Text);
string b = Convert.ToString(textBox2.Text);
try
{
    //String typ = "1BHK";
    string str = "select propno,owner,address,phoneno,price,status,dimension,type from property where price between " + a + " and " + b ;

    OleDbDataAdapter DAap = new OleDbDataAdapter(str, connString);
    DataSet DS = new DataSet();
    DAap.Fill(DS, "Property");
    DataTable DT = DS.Tables[0];
    dataGridView1.DataSource = DT;
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message.ToString(), "Real Estate...       ", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
 
Share this answer
 
What is the datatype of price ?

Please check if it is same as of a and b or vice versa.

Regards.
 
Share this answer
 
C#
string str = "select propno,owner,address,phoneno,price,status,dimension,type from property where price between " + a + " and " + b + " ";
 
Share this answer
 
Comments
Raghavendra M 12-Oct-13 10:44am    
Thank u . . , i got it . .
Change the coloumn from number data type to int in the Database table
 
Share this answer
 
Comments
Raghavendra M 5-Oct-13 9:00am    
no i m using MSAccess database , Number is the only type
Naresh1277 5-Oct-13 12:26pm    
have you checked on msdn site?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900