使用Int值自动完成
本文关键字:Int 使用 | 更新日期: 2023-09-27 17:58:06
我有一个为名称(字符串)自动完成的方法,我想创建另一个方法来完成Int Type,我尝试了一下,但它说不能将LIKE仅用于字符串的int类型
void AutoComplete()
{
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection Collection = new AutoCompleteStringCollection();
con.Open();
cmd = new SqlCommand("select * from stagiaire",con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
nom = dr.GetString(1).ToString();
Collection.Add(nom);
}
textBox1.AutoCompleteCustomSource = Collection;
con.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("nom like '{0}%'", textBox1.Text);
dataGridView1.DataSource = dv;
}
private void Form1_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from stagiaire",con);
da.Fill(dt);
}
对于DataType为INTEGER的列,使用如下查询:
select * from Table where Id like 1;
或者将其转换为varchar:
select * from Table where CAST(Id AS VARCHAR(45)) like '1%'