Solved

Using getDate MSSQL function in C# code.

Posted on 2004-08-04
3
857 Views
Last Modified: 2012-06-27
Im new to SQL/c#.  Here is what I'm trying to do.

strSQL = "INSERT t_customers VALUES (" +
                              PrepareStr(txt_first_name.Text) + "," +
                              PrepareStr(txt_last_name.Text) + "," +
                              PrepareStr(txt_user_name.Text) + "," +
                              PrepareStr(txt_password.Text) + "," +
                              PrepareStr(txt_address.Text) + "," +
                                                         
Next I want to include  getDate, so I can get the date from the SQL server and insert it into the next field in the table, but I'm not sure how to go about doing this.

Thanks in advance,
Sean
0
Comment
Question by:sean-keys
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
dishanf earned 100 total points
ID: 11723017
PrepareStr(txt_address.Text) + ", GETDATE() " +
0
 
LVL 8

Expert Comment

by:dishanf
ID: 11723021
OR if you have more columns, put "," at the end
PrepareStr(txt_address.Text) + ", GETDATE() ," +
0
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 11723040
An advice, use String.Format to make code more readable and easy to update

strSQL = String.Format("INSERT t_customers VALUES ({0}, {1}, {2}, {3}, {4} , GETDATE())",PrepareStr(txt_first_name.Text), PrepareStr(txt_last_name.Text), PrepareStr(txt_user_name.Text), PrepareStr(txt_password.Text),  PrepareStr(txt_address.Text));

Look for String.Format on MSDN

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now