Solved

Using getDate MSSQL function in C# code.

Posted on 2004-08-04
3
870 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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