Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void CoursesLookUp() //2-Step Get Student List with there cities names from SQl Server
       {



            CoursesDataSet.Clear();
            CourseCollection.Clear();
            GrdCourses.ItemsSource = CourseCollection;
            var con1 = new SqlConnection(Connectionstring);
            SqlCommand cmd1;
            cmd1 = new SqlCommand(Sql,con1);
            SqlDataAdapter da1;
            da1 = new SqlDataAdapter(cmd1);
            da1.Fill(CoursesDataSet);
            for (int i = 0; i < CoursesDataSet.Tables[0].Rows.Count; i++)
            {


                CourseCollection.Add(new Course()
                {
                    CourseId = int.Parse(CoursesDataSet.Tables[0].Rows[i][0].ToString()),
                    Year = CoursesDataSet.Tables[0].Rows[i][11].ToString(),
                    LevId = int.Parse(CoursesDataSet.Tables[0].Rows[i][12].ToString()),
                    Levle = CoursesDataSet.Tables[0].Rows[i][13].ToString(),
                    SemId = int.Parse(CoursesDataSet.Tables[0].Rows[i][9].ToString()),
                    Semester = CoursesDataSet.Tables[0].Rows[i][10].ToString(),
                    Price = Convert.ToDecimal(CoursesDataSet.Tables[0].Rows[i][4].ToString()),
                    CurrencyId = int.Parse(CoursesDataSet.Tables[0].Rows[i][5].ToString()),
                    Currency = CoursesDataSet.Tables[0].Rows[i][6].ToString(),
                    Rate = Convert.ToDecimal(CoursesDataSet.Tables[0].Rows[i][7].ToString()),
                    Start = Convert.ToDateTime(CoursesDataSet.Tables[0].Rows[i][1].ToString()).Date,
                    End = Convert.ToDateTime(CoursesDataSet.Tables[0].Rows[i][2].ToString()).Date,
                    Hours = Convert.ToDecimal(CoursesDataSet.Tables[0].Rows[i][3].ToString()),
                    Status = CoursesDataSet.Tables[0].Rows[i][8].ToString()


                });


            }
            GrdCourses.ItemsSource = CourseCollection;

       }


What I have tried:

End = Convert.ToDateTime(CoursesDataSet.Tables[0].Rows[i][2].ToString()).Date,


This return The date + time as
4/1/2019 12:00:00 AM


What i want like this
4/1/2019
Posted
Updated 9-Jan-19 9:48am
Comments
[no name] 9-Jan-19 15:47pm    
Your code is unmaintainable.

You should be using table names, column names and row references.

1 solution

End = Convert.ToDateTime(CoursesDataSet.Tables[0].Rows[i][2].ToString()).ToShortDateString(),


The key to this solution is in the following snippet:
ToShortDateString()
There are other ways to format the string too, but I think this is what you were looking for.
 
Share this answer
 
v3
Comments
Rabee3-F1.787545 9-Jan-19 16:51pm    
End is a DateTime i tried my best to keep it as DateTime but as you said i have to change it in the class to string
Course.End

Thanks alot

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