我有这个方法自动完成名称(字符串), 我想创建完成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);
}
答案 0 :(得分:0)
使用如下查询:
select * from Table where Id like 1;
或将其转换为varchar:
select * from Table where CAST(Id AS VARCHAR(45)) like '1%'