再上述 kanban窗口中 根据listbox1中列出的mo_no利用sql语句select sta_dd as 生产日期 mo_no as 制令单号mrp_no as 生产成品sta_dd as 预计开工日期end_dd as 结束日期qty1 as 生产数量qty_fin as 缴库数量id_no as bom配方 from mf_mo where mo_no = listbox的item
您可以使用以下代码将数据显示到DataGridView1中:
string selectedMoNo = listbox1.SelectedItem.ToString();
string sql = "select sta_dd as '生产日期', mo_no as '制令单号', mrp_no as '生产成品', sta_dd as '预计开工日期', end_dd as '结束日期', qty1 as '生产数量', qty_fin as '缴库数量', id_no as 'bom配方' from mf_mo where mo_no = @MoNo";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(sql, connection))
{
command.Parameters.AddWithValue("@MoNo", selectedMoNo);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
dataGridView1.DataSource = dataTable;
}
}
在上述代码中,connectionString是连接数据库的字符串,您需要根据实际情况进行设置。首先,获取选中的制令单号(selectedMoNo),然后使用参数化的SQL查询语句,将选中的制令单号传递给SQL语句。使用SqlDataAdapter执行查询并将结果填充到DataTable中,最后将DataTable设置为DataGridView1的数据源
原文地址: https://www.cveoy.top/t/topic/iKth 著作权归作者所有。请勿转载和采集!