数据类型未匹配 [英] Data type miss match
本文介绍了数据类型未匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码是:
my code is :
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.
推荐答案
不应该是这样吗?
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;
PS:推荐使用存储过程而不是形成c#字符串查询。它们暴露于SQL注入。
P.S.: It's recommended to use Store Procedures instead of forming c# string queries. They are exposed to SQL Injection.
试试这个,
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);
}
价格的数据类型是什么?
请检查一下与a和b相同,反之亦然。
问候。
What is the datatype of price ?
Please check if it is same as of a and b or vice versa.
Regards.
这篇关于数据类型未匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文