Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a column in database in sql server 2012 that his type is Time (7)
and i want to use it in asp.net but i don't know how.!!

i want from this Time the hours and minutes.
Posted
Comments
DamithSL 29-Dec-14 12:52pm    
what have you tried so far?
Bestfofo 29-Dec-14 13:19pm    
trans.Clear();



SqlCommand COMM = new SqlCommand("select *from [DDD]");
COMM.Connection = cnn;
cnn.Open();

try
{
SqlDataReader dr = COMM.ExecuteReader();
while (dr.Read())
{
Transaction x = new Transaction();

x.UserName = dr.GetString(0);
x.Action = dr.GetString(1);

x.Time = dr.GetTimeSpan(2);

if (!(dr["ToAccount"].Equals(System.DBNull.Value)))
{
x.ToAccount = dr["ToAccount"].ToString();
}
if (!(dr["FromAccount"].Equals(System.DBNull.Value)))
{
x.FromAccount = dr["FromAccount"].ToString();
}
x.Amount = dr[6] != null ? dr.GetDecimal(5) : 0;
trans.Add(x);
}


i try this but i didn't use the type Time before and i get error in using timespan

These two articles are show you how to map SQL time data type to .NET data type...
http://msdn.microsoft.com/en-us/library/ms131092.aspx[^]
http://msdn.microsoft.com/en-us/library/bb675168.aspx[^]
 
Share this answer
 
Comments
Bestfofo 29-Dec-14 13:21pm    
thanx, i have already see them but i didn't know how to get the time using timespan
Kornfeld Eliyahu Peter 29-Dec-14 13:27pm    
To get time from TimeSpan, you can use TimeSpan.Hours and TimeSpan.Minutes...
http://msdn.microsoft.com/en-us/library/system.timespan(v=vs.110).aspx
 
Share this answer
 

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