Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load data from database to Datagridview C#

Status
Not open for further replies.

hoangluc19

Programmer
Nov 18, 2019
10
VN
Hello everyone,all my data uploaded in datagridview 2 is for easy viewing just need to get information. actually not uploaded. What to do after I book the meeting room in another form with the time column data: start, stop, roomname will display on datagridview1 which means that after you book the meeting room, you can look at datagridview1 to know what time is the meeting room as shown? I only know how to load data up the same form as the code below, but from one booking form to another, I don't know how to display it. hope you guys can guide me, thank you very much. I have api including details of data tables as each table, do not have to get data directly on the database management system, only use api
private void selectAreaColor()
{
string starttime1 = cboStarttime.Text;//I don't know how to declare it to get it from the database
string stoptime1 = cboStoptime.Text;//I don't know how to declare it to get it from the database
// Get the start time and end time inputs and the selected meeting room
DateTime startTime = DateTime.ParseExact(starttime1, "HH:mm", null);
DateTime endTime = DateTime.ParseExact(stoptime1, "HH:mm", null);
string selectedRoom = cboRoom.SelectedItem.ToString();//I don't know how to declare it to get it from the database

// Loop through the rows in the DataGridView and find the matching row

foreach (DataGridViewRow row in grdMeeting.Rows)
{
if (row.Cells[0].Value.ToString() == selectedRoom)
{
int rowIndex = row.Index;
// Loop through the columns and compare the start and end times with the time slots
for (int i = 1; i < grdMeeting.Columns.Count; i++)
{
DateTime columnTime = DateTime.ParseExact(grdMeeting.Columns.HeaderText, "HH:mm", null);
string _HeaderText = grdMeeting.Columns.Name.ToString();
if (startTime == columnTime)//|| endTime == columnTime
{

grdMeeting.Rows[rowIndex].Cells[_HeaderText].Style.BackColor = Color.Blue;

if (startTime == endTime)
return;
else
startTime = startTime.AddMinutes(30);
}
}
}
}
}
ask_zh5lkq.png
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top