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
Solved

Using getDate MSSQL function in C# code.

Posted on 2004-08-04
3
861 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

839 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