How do I format the two strings Data and Somma in this context?
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from Pagamenti ORDER BY [Data] DESC";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "Pagamenti");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DropDownList1.Items.Add(ds.Tables[0].Rows[i]["Id"] +
" --|-- " + ds.Tables[0].Rows[i]["Data"].ToString() +
" --|-- " + ds.Tables[0].Rows[i]["Somma"]);
}
con.Close();
ToString() is not taking anything and I need respectively "dd/MM/yyyy" and "R #.###".
I guess that is because the type of the values returned is object
, which indeed has not parameters.
Try to cast the object to the right type and call ToString
again.
Like this:
Convert.ToDateTime(ds.Tables[0].Rows[i]["Data"]).ToString("dd/MM/yyyy")
Or let the string.Format
handle it:
string.Format("{0:dd/MM/yyyy}", ds.Tables[0].Rows[i]["Data"])
string.Format("{0} --|-- {1} --|-- {2}",ds.Tables[0].Rows[i]["Id"].ToString(),ds.Tables[0].Rows[i]["Data"].ToString(),ds.Tables[0].Rows[i]["Somma"].ToString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With