Datagridview:从数据库到DateTimePicker的日期

时间:2016-01-03 08:35:10

标签: c# sql-server database datetimepicker

我有两种形式,我必须在第一种形式的dategridview中获取日期:

private void checkinToolStripMenuItem1_Click(object sender, EventArgs e)
{
    int rowindex = dgCheckin.CurrentCell.RowIndex;
    int reserveindex = 10;
    string statindex = dgCheckin.Rows[rowindex].Cells[reserveindex].Value.ToString();
    int roomindex = 5;
    string roomNum = dgCheckin.Rows[rowindex].Cells[roomindex].Value.ToString();

    if (statindex == "Reserved")
    {
        frmCheckIn recheckin = new frmCheckIn(user, true, roomNum);
        recheckin.ShowDialog();
    }
    else if (statindex == "Cancelled")
    {
        MessageBox.Show("This " + roomNum + " is already cancelled.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

然后日期将以第二种形式放入datetimepicker:

public void loadReservation()
{
    con.Open();
    string reservetable = "tblReservation";
    string reservequery = "SELECT*FROM tblReservation WHERE RoomNum = '" + this.roomnum + "' AND Status = 'Reserved'";
    da = new SqlDataAdapter(reservequery, con);
    da.Fill(ds, reservetable);
    int counter = 0;

    if (counter < ds.Tables[reservetable].Rows.Count)
    {
        string dateuse = ds.Tables[reservetable].Rows[counter]["DateOfUse"].ToString();
        dtpCheckIn.Text = dateuse;
    }
    con.Close();
}

但是datetimepicker没有改变/与数据库中的相同。

0 个答案:

没有答案