Link to home
Start Free TrialLog in
Avatar of sean-keys
sean-keys

asked on

Using getDate MSSQL function in C# code.

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
ASKER CERTIFIED SOLUTION
Avatar of Dishan Fernando
Dishan Fernando
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OR if you have more columns, put "," at the end
PrepareStr(txt_address.Text) + ", GETDATE() ," +
Avatar of s_sansanwal
s_sansanwal

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