Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a button that insert values in a database row. Each row in my database will represent a day. now i want to insert my values in 7 of my databse rows or mybe 2 aleast. each row has a time slot, date, ID, and status, how can i insert these in my rows?

Check my code below

This code alows me to insert only in a single row.

protected void btnSubmit_Click(object sender, EventArgs e)
{
    int empRecNumber;
    if (DatePicker.SelectedDate.ToShortDateString() == "1/1/0001")
    {
        MessageBox.Show("Please Choose date to view Employee Slots", "??", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else if(ddlEmployeeID.SelectedValue==".:Select Employee:.")
    {
        MessageBox.Show("Please Choose an employee", "??", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else
    {
        ddlEmployeeID_SelectedIndexChanged(sender, e);
        foreach (GridViewRow rowItem in grvSlots.Rows)
        {
            CheckBox chk = (CheckBox)(rowItem.Cells[0].FindControl("CheckBox1"));
            if (chk.Checked)
            {
                string slotName = (grvSlots.DataKeys[rowItem.RowIndex]["SlotName"].ToString());
                Session["date"] = DatePicker.SelectedDate.ToShortDateString();
                empRecNumber = Convert.ToInt32(Session["idnumber"]);
                const string status = "a";

                ClsAppointmentSlots slots = new ClsAppointmentSlots(slotName, Session["date"].ToString(), Convert.ToInt32(empRecNumber), status);
                MessageBox.Show(slotName + "\n" + Session["date"].ToString() + "\n" + Convert.ToInt32(empRecNumber)+ "\n" +status);
                systemBusinessLayer.setSlot(slots);
                chkAll_CheckedChanged(sender, e);
                chk.Checked = false;
            }
        }
    }
    else
    {
        System.Windows.Forms.MessageBox.Show("Sorry you can not an appointment slot for previous days");
    }
}
Posted
Updated 22-Jul-11 1:56am
v2

1 solution

Run it under the debugger. You'll find the problem.
 
Share this answer
 
Comments
Anele Ngqandu 22-Jul-11 7:59am    
There is no problem except i dont knw how to insert same values in multiple rows Sir
Reiss 22-Jul-11 9:50am    
I would argue that there are a lot of coding issues with the code as provided, but that won't solve your problem.

Just to get you started

change this
if (DatePicker.SelectedDate.ToShortDateString() == "1/1/0001")
to this
if (DatePicker.SelectedDate.Equals(DateTime.MinValue))

change this
else if(ddlEmployeeID.SelectedValue==".:Select Employee:.")
to something index based

move this
const string status = "a";
outside your foreach loop

etc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900