期限切れの書籍を計算するコマンドがありますが、特定の人だけに適用したいです。私のコマンドは、表 Borrowbook に罰金を挿入することです。また、datagridview がデータを表示するボタンにコードを入れます。私のコードは次のようなものです:
SqlConnection con = new SqlConnection(constring);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT [Student ID], ISBN, Title, Date, [Due Date], Penalty FROM Borrowbook;", con);
try
{
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataTable Records = new DataTable();
sda.Fill(Records);
BindingSource bsource = new BindingSource();
bsource.DataSource = Records;
dataGridView1.DataSource = bsource;
sda.Update(Records);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
if (dateTimePicker2.Value < DateTime.Now)
{
cmd.CommandText = "INSERT INTO Borrowbook (Penalty) VALUES (@Penalty)";
SqlParameter p1 = new SqlParameter("@Penalty", SqlDbType.Int);
p1.Value = 50;
cmd.Parameters.Add(p1);
cmd.ExecuteNonQuery();