Problema mostrando fecha como string, URGENTE!

<span id="ctl00_ContentPlaceHolder1_dlst_Tema_TextoLabel">Hola a todos,
tengo un gran problema, estoy haciendo una consulta desde SQL, la idea
es mostrar en la tabla los datos de las fotografías, todos salen bien ,
excepto la fecha, no puedo convertir un string en DateTime, necesito
que me ayuden, es urgente porfavor, a continuación les dejo el código:
                Con.Open();
                SqlCommand cmd = new SqlCommand(@"SELECT merchandising.ROWID, merchandising.CustomerID,
 merchandising.Notes, customersmaster.customername, merchandising.PictureLogged
FROM Merchandising, customersmaster where customersmaster.customerid = Merchandising.customerid and " +
                    @"SalespersonID = '"+salespersonID+"' AND PictureLogged BETWEEN '"+fromDate+"' "+
                    @"AND '"+toDate+"'", Con );
                SqlDataReader dr = cmd.ExecuteReader();
                Int32 rowid = -1;
                int irow = 0;
                while( dr.Read() )
                {
                    rowid = dr.GetInt32(0);
                    HtmlTableRow row = new HtmlTableRow();
                    if ( irow % 2 == 0 )
                        row.BgColor = "#ff0000";
                    else
                        row.BgColor = "#0000ff";
                    // Adding the picture part
                    HtmlTableCell cell = new HtmlTableCell();
                cell.InnerHtml = "<img
src=\"DisplayBeforeNAfter.aspx?ImgID=1&height=320&width=240&rowid="+rowid+"\">";
                    row.Cells.Add( cell );
                    cell = new HtmlTableCell();
                cell.InnerHtml = "<img
src=\"DisplayBeforeNAfter.aspx?ImgID=2&height=320&width=240&rowid="+rowid+"\">";
                    row.Cells.Add( cell );
                    Table1.Rows.Add( row );
                  ...
                    if (dr.IsDBNull(4))
                        cell.InnerText = "PictureLogged";
                    else
                        DateTime.Parse("cell");
                        cell.InnerText = dr.GetDateTime(4); ----:: Este es el problema. AYUDA
                        row.Cells.Add(cell);
                    row.Cells.Add(cell);
                    Table1.Rows.Add(row);
                    irow++;
                }
            }
        }
</span>

1 respuesta

Respuesta
1
Que formato tiene tu string de fecha? me ha pasado que de string a DateTime tiene que estar con el formato MM/dd/yyyy probablemente sea lo mismo para DateTime a string.
ya intentaste tambien poniendo dr.GetDateTimer(4).ToString();
Despues de mucho intentarlo lo logré como me indicaste, muchas gracias
cell.InnerText = dr.GetDateTime(4).ToString("MM/dd/yyyy - HH:mm:ss ");

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas