How do insert into a DB

G

Guest

I have a database field of type datetime. This field should store a system
time when a record is inserted. The other fields in the record are bound to a
control and I have no problems with them. I tried setting the datetime field
with a default value using getdate(), but it still does not work. How can I
use a statement similar these beow to achieve this?

My current code:

<InsertParameters>
<asp:ControlParameter Name="BillingAddress" Type="String"
ControlID="BillingAddress" PropertyName="Text" />
<asp:ControlParameter Name="BillingCity" Type="String"
ControlID="BillingCity" PropertyName="Text" />

<!-- This is where my problem is !-->
<asp:ControlParameter Name="SignUpDate" Type="String" .... />
 
G

Guest

I have a database field of type datetime. This field should store a system
time when a record is inserted. The other fields in the record are bound to a
control and I have no problems with them. I tried setting the datetime field
with a default value using getdate(), but it still does not work. How can I
use a statement similar these beow to achieve this?

My current code:

<InsertParameters>
<asp:ControlParameter Name="BillingAddress" Type="String"
ControlID="BillingAddress" PropertyName="Text" />
<asp:ControlParameter Name="BillingCity" Type="String"
ControlID="BillingCity" PropertyName="Text" />

<!-- This is where my problem is !-->
<asp:ControlParameter Name="SignUpDate" Type="String" .... />

SQL Server?

I think, you can specify the date in the statement:

InsertCommand="INSERT INTO... getdate()....

You can also create a constraint for the table, it will add a date
automatically

ALTER TABLE [tablename] ADD
CONSTRAINT [somename] DEFAULT (getdate()) FOR [columnname]
GO
 
G

GroupReader

I agree with Alexey. Also, I wanted to add that maybe your problem is
that your are missing the quotes around the date. If you are sending
a date to SQL Server as a string (which is fine) be sure to treat it
like a string and put quotes around it.
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top