true db grid and date / time

S

Stephanie Stowe

I have a column in which I enter a time. The NumberFormat is short time. So
I can enter 8:00 am. Lovely. This grid is bound to a dataset. The underlying
data in the dataset is a SQL Server datetime. When I am entering data I
enter JUST the time. In the AfterUpdate event of the grid, I update the data
adapter:

da.Update(ds);

(note C#).

The date that gets stored to SQL is the current date. No wonder. I have
another column in the grid which contains the date that I want to save. (The
user enters the date in one column and the time in the other. It makes
sense. Really.)

My question is, before updating the data adapter, do I attempt to edit the
value in the data set? The grid column value to which the dataset is bound?

I am new to both true db grid, ado.net and windows forms (oh joy).

I cannot tell what the type of the value in the column is.

tdbgTime.Columns[2].Value LOOKS like a DateTime.

When I ? in the Command Window, I see

? tdbgTime.Columns[2].Value
{10/11/2004}
[System.DateTime]: {10/11/2004}

When I do a Console.WriteLine(tbbgTime.Columns[2].Value) I see

10/11/2004 8:00:00 AM

I was going to make a DateTime variable to store the value

DateTime t = new DateTime();
t = tdbgTime.Columns[2].Value;

But on the second line, I see a build error "Cannot implicitly convert type
'object' to 'System.DateTime'

But it looks to me like it IS a date time. I have found no cast that will
work since it does not seem that the compile can tell what the value's type
is.

Can anyone knock me upside the head since I am clearly not seeing something
fairly obvious. (I think)

THANKS!
 
S

Stephanie Stowe

Geeees. This happens all the time. As soon as I post, I figure it out. I put

private void tdbgTime_BeforeUpdate(object sender,
C1.Win.C1TrueDBGrid.CancelEventArgs e)
{
// set the date for the start and end datetime fields
DateTime tStart = new DateTime();
DateTime tEnd = new DateTime();
tStart = System.Convert.ToDateTime(tdbgTime.Columns[2].Value);
tEnd = System.Convert.ToDateTime(tdbgTime.Columns[3].Value);

DateTime tNewStart = new DateTime(dWorkingDate.Year,
dWorkingDate.Month, dWorkingDate.Day,
tStart.Hour, tStart.Minute, tStart.Second, 0);
DateTime tNewEnd = new DateTime(dWorkingDate.Year,
dWorkingDate.Month, dWorkingDate.Day,
tEnd.Hour, tEnd.Minute, tEnd.Second, 0);

tdbgTime.Columns[2].Value = tNewStart;
tdbgTime.Columns[3].Value = tNewEnd;


}

In the before update event of the grid. It is lovely. Thanks ahyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top