ShmulikCohen ShmulikCohen - 4 months ago 17
SQL Question

Cant execute SQL query , with Convert(Date,GetDate()) , C# WinForms

I'm trying to execute this query

"INSERT INTO Orders Values (" + OrderId.Text + ',' + IDCustTextBox.Text + ',' + CustName.Text + ",SELECT CONVERT(DATE, GETDATE()))"

Answer

Since you are using the INSERT INTO ...VALUES, you don't need a SELECT. You will use:

"INSERT INTO Orders 
 Values ('" + OrderId.Text + "','" + IDCustTextBox.Text + "','" + CustName.Text + "',GETDATE())"

By the way, you do not need to convert GETDATE() to a date because it is already a date.