C# 如何从数据库中选择C中的combobox来获得前3个值
我想选择组合框项目,并根据我在c 2010 express中的选择在datagridview上显示前3种可能性。我用C创建了数据库C# 如何从数据库中选择C中的combobox来获得前3个值,c#,sql,database,data-files,C#,Sql,Database,Data Files,我想选择组合框项目,并根据我在c 2010 express中的选择在datagridview上显示前3种可能性。我用C创建了数据库 private void add_button_Click(object sender, EventArgs e) { SqlConnection sqlcon = new SqlConnection(); sqlcon.ConnectionString = @"Data Source=.\SQLE
private void add_button_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Mystudies\C#\SQL Database\MakerSelectionDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
// insert Logic
sqlcon.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from makerinfo Where [Equipment Type] = '" + equipmenttype_combobox.Text.Trim() + "' and Plant='" + plant_combobox.Text.Trim() + "'", sqlcon);
// I could not combine this code to combobox selection.
// SqlDataAdapter eval = new SqlDataAdapter("select top 3 safety from makerinfo order by Safety desc", sqlcon);
DataTable dt = new DataTable();
SqlDataAdapter db = new SqlDataAdapter();
sda.Fill(dt);
datagridview.DataSource = dt;
sqlcon.Close();
}
为什么不使用Select top૩ 并通过Saftey Desc在您的QueryTX中订购,以获得您的回复。您是否有任何示例链接或文档?我不知道如何将SQL查询与interface.SqlDataAdapterselect top结合起来运行૩ 来自makerinfo的安全性,其中[Equipment Type]='+equipmenttype_combobox.Text.Trim+'和Plant='+Plant_combobox.Text.Trim+'由Saftey desc、sqlcon订购;你试过这个吗?成功了:非常感谢。现在我将尝试获取所有行信息。