Solved

Using getDate MSSQL function in C# code.

Posted on 2004-08-04
3
863 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:
Dishan Fernando earned 100 total points
ID: 11723017
PrepareStr(txt_address.Text) + ", GETDATE() " +
0
 
LVL 8

Expert Comment

by:Dishan Fernando
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 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