C# 如何在库存系统中扫描和显示过期产品
我们正在制作一个库存系统,该系统将显示5天内到期的产品列表。我不知道如何解释清楚,但我会尽力的。我的想法是它应该扫描所有的记录,那些将在5天内过期的记录将被显示出来。我应该用什么来做这个,我应该用for循环,如果不是的话。非常感谢。我使用的语言是c 这是我到目前为止所做的C# 如何在库存系统中扫描和显示过期产品,c#,C#,我们正在制作一个库存系统,该系统将显示5天内到期的产品列表。我不知道如何解释清楚,但我会尽力的。我的想法是它应该扫描所有的记录,那些将在5天内过期的记录将被显示出来。我应该用什么来做这个,我应该用for循环,如果不是的话。非常感谢。我使用的语言是c 这是我到目前为止所做的 public void all() { SqlConnection MySqlConnection; DataTable p_table = new DataTable();
public void all()
{
SqlConnection MySqlConnection;
DataTable p_table = new DataTable();
MySqlConnection = new SqlConnection("Data Source=christina\\sqlexpress;Initial Catalog=cafe_inventory;User ID=sa;Password=tina;");
MySqlConnection.Open();
SqlCommand command1 = new SqlCommand("Select * from inventory", MySqlConnection);
//Clear the datatable to prevent duplicate generation of data in gridview.
p_table.Clear();
SqlDataAdapter m_da = new SqlDataAdapter("Select * from inventory", MySqlConnection);
//DataSet ds = new DataSet();
//DataTable dtable = ds.Tables["empinfo1"];
m_da.Fill(p_table);
// Clear the ListView control
//listView3.Items.Clear();
// Display items in the ListView control
for (int i = 0; i < p_table.Rows.Count; i++)
{
DataRow drow = p_table.Rows[i];
// Only row that have not been deleted
if (drow.RowState != DataRowState.Deleted)
{
// Define the list items
ListViewItem lvi = new ListViewItem(drow["bnum"].ToString());
lvi.SubItems.Add(drow["pnum"].ToString());
lvi.SubItems.Add(drow["pname"].ToString());
lvi.SubItems.Add(drow["descr"].ToString());
lvi.SubItems.Add(((DateTime)drow["dater"]).ToShortDateString());
//lvi.SubItems.Add(drow["exp"].ToString());
lvi.SubItems.Add(((DateTime)drow["exp"]).ToShortDateString());
lvi.SubItems.Add(drow["qt"].ToString());
// Add the list items to the ListView
listView2.Items.Add(lvi);
}
}
}
->这将显示所有产品。尝试以下操作:
DateTime CurrentDate = DateTime.Now;
string query = "select * from inventory where Exp
< (Select DATEADD(day,5,@CurrentDate))";
SqlCommand command = new SqlCommand(query);
command.Parameters.AddWithValue(@CurrentDate ,CurrentDate);
SqlDataAdapter m_da = new SqlDataAdapter(command , MySqlConnection);
让我们看看您到目前为止做了什么您正在使用数据库吗?是的,我正在使用MS SQL 2008@SudhakarTillapudi@christina当前位置查看下面的答案。如果您需要其他信息,请与我们联系know@SudhakarTillapudi非常感谢。我试试看。