Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SqlCommand cmd = new SqlCommand("SELECT * FROM [t_memsch] where [m_memcode]='" + m_memcode_input.Text + "'", conn);
                SqlDataAdapter sda1 = new SqlDataAdapter(cmd);
                DataTable ds1 = new DataTable();


                sda1.Fill(ds1);                

                try
                {   
                    //int temp = ds1.Rows.Count

                    decimal[,] allowance = new decimal[31,6]; //[day, session]

                    for (int row = 0; row < 31; row++)
                    {
                        for (int col = 0; col < 6; col++)
                        {
                            allowance[row, col] = 0;
                        }
                    }

                    for(int temp = ds1.Rows.Count; temp > 0; temp--)
                    {
                        temp--;
                        string date1 = ds1.Rows[temp]["m_schdate"].ToString();
                        temp++;

                        if (chk_date(date1, conn))
                        {
                            MessageBox.Show(date1);

                            if (chk_late(date1, conn))
                            {
                                MessageBox.Show("Good Boy!!");
                                
                                //int day = (int)cmd.ExecuteScalar();

                                allowance[28,3] = 30;
                                allowance[29, 1] = 12.7M;
                            }
                            else 
                            {
                                MessageBox.Show("Late! No pay.");
                                allowance[28,3] = 0;
                            }


There is a column call "t_scantime" in my table [t_memsch], and the format of t_scantime is "12-31-2011 10:30:00"

Now i want to insert the day only from "t_scantime" into my array's day column - allowance[day,session], may anyone please give me some helps or idea?
P.S. wanna do the insert statement under "MessageBox.Show("Good Boy!!");" this line.

pleaseeeee.
Posted
Updated 3-Jan-12 16:29pm
v2

string dttime = "12-31-2011 10:30:00";
            DateTime dt = Convert.ToDateTime(dttime);
            dttime = dt.Day.ToString();
 
Share this answer
 
Comments
tomy_hkcg 3-Jan-12 23:24pm    
thanks you.
anushripatil 3-Jan-12 23:26pm    
You can have this,
int dttt = dt.Day;
tomy_hkcg 3-Jan-12 23:31pm    
It's solved. thanks
Please change your code as per below code

Datetime date1 = convert.toDate(ds1.Rows[temp]["m_schdate"].ToString());
temp++;
if (chk_date(date1.tostring(), conn))
{
MessageBox.Show(date1.tostring());
if (chk_late(date1.tostring(), conn))
{

int day = date1.day;
allowance[28,3] = 30;
allowance[29, 1] = 12.7M;
}
else
{
MessageBox.Show("Late! No pay.");
allowance[28,3] = 0;
}


Hope this will help.
 
Share this answer
 
v2
Comments
tomy_hkcg 3-Jan-12 23:30pm    
work perfectly, thanks
Nigam Patel 3-Jan-12 23:52pm    
welcome

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