Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I have created form from insert daily job (date + time )for employees
start time for job is 8:00 AM
and end time for job is 18:00 PM
I have two datetimepicker
datetimepicker1 is called StartTimePicker for start time
datetimepicker2 is called EndTimePicker for end time
in properties for StartTimePicker I set Format= custom and
custom format = 08:00 MM/dd/yyyy
in properties for EndTimePicker I set Format = custom and
custom foramt = 18:00 MM/dd/yyyy
I created the following class for insert rows
C#
 public static bool Addtimerow(DateTime starttime, DateTime endtime )
        {
            bool b;
            string strconn = AlShehabi.Properties.Settings.Default.NewSalariesDBConnectionString;
            SqlConnection conn = new SqlConnection(strconn);

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            SqlCommand cmd = new SqlCommand("INSERT INTO JobHours(Worker_ID)            
Select Worker_ID FROM Workers;", conn);
       
            int i = cmd.ExecuteNonQuery();

            if (i <= 0)
                b = false;
            else
                b = true;
            conn.Close();
            return b;
        }

whent btnadd_click event I want to add in JobHours table all workers names and starttime for job (date +time ) and endtime for job
for example
C#
Mark 3/15/2014 08:00 3/15/2014 18:00 
Jack 3/15/2014 08:00 3/15/2014 18:00 

and so on
when btnadd_click event I wrote
C#
private void btnadd_Click(object sender, EventArgs e)
        {
           DateTime Start_Work = StartTimePicker.Value;
            DateTime End_Work = EndTimePicker.Value;
            if (dailyworkerhours.Addtimerow(Start_Work,End_Work))
            gridviewjobhours.EndEdit();
}

the code works but my problems is when btnadd_click
workers names is inserted in the gridview without starttime for job and endtime for job
for example
Mark
Jack
how to solve this problem?
Posted
Updated 29-Sep-14 1:00am
v2
Comments
Sinisa Hajnal 29-Sep-14 7:07am    
You're not using Start_Work and End_work in your Addtimerow function, you're just inserting Worker_id...I'd say your code works as you wrote :)
firaso2014 29-Sep-14 7:10am    
what must I Write in Addtimerow function for the code works
Richard MacCutchan 29-Sep-14 7:47am    
You need to add the timer values to the database record.
firaso2014 29-Sep-14 8:05am    
how to add the timer values ?
when I insert only worker_id from workers table becuase workers table don't contain timer values
only I want to select worker_id from workers table and insert it in jobhours table while timer values I want to insert them in jobhours table without select
[no name] 30-Sep-14 20:02pm    
If that is what want to do, then doesn't make sense to write an INSERT query to insert the hours into your jobhours table then?

1 solution

try code
DateTime start1 = starttime.Value;
start1 = new DateTime(start1.Year, start1.Month, start1.Day);
DateTime end1 = endtime .Value;
end1 = new DateTime(end1.Year, end1.Month, end1.Day);

string start = start1.ToString("MM/dd/yyyy");
string end = end1.ToString("MM/dd/yyyy");

Use these Start1 and end1 value and try
 
Share this answer
 

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