0

I need to retrieve the Date only from Microsoft SQL Server and insert into Listview the code that i used was this

  SqlCommand cmd4 = new SqlCommand();
                    SqlConnection cn = new SqlConnection();
                    cn.ConnectionString = ("Data Source = LOPEZ-PC\\SQLEXPRESS;Initial Catalog=softwareengineering; Integrated security= TRUE");
                    cmd4.CommandText = "SELECT * FROM [rawinventory] ";
                    cn.Open();
                    //SqlDataReader dr = cmd4.ExecuteReader();
                    cmd4.Connection = cn;
                    SqlDataAdapter dat = new SqlDataAdapter(cmd4);
                    DataTable dt = new DataTable();
                    dat.Fill(dt);

                    foreach (DataRow myRow in dt.Rows)
                    {
                        ListViewItem item = new ListViewItem(myRow["Rawmat_ID"].ToString());
                        item.SubItems.Add(myRow["Category"].ToString());
                        item.SubItems.Add(myRow["Item"].ToString());
                        item.SubItems.Add(myRow["Quantity"].ToString());
                        item.SubItems.Add(myRow["Unit"].ToString());
                        item.SubItems.Add(myRow["Cost"].ToString());
                        item.SubItems.Add(myRow["Date_Received"].ToString());
                        item.SubItems.Add(myRow["Status"].ToString());
                        listView1.Items.Add(item);
                        cn.Close();
                    }

The code when I insert the value of date was this

cmd.Parameters.AddWithValue("@Date_Received", SqlDbType.Date).Value = dateTimePicker2.Value;

The problem that I'm having is that when it retrieves the data from Microsoft SQL server into the List view the format of the Date Column is e.g 01/10/2012 12:00. Can someone help me thank you in advance!

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by nmaillet
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.