-1
I have the following variable
DateTime ContaRecebeDataPagto = Convert.ToDateTime(dgOrigem.SelectedRows[0].Cells[2].Value.ToString());
She gets a value from DataGrid
, in some cases the date of payment, and in other cases has nothing as it has no payment.
And I got the following INSERT
that I do with the result of DataGridView
:
//INSERT TABELA DESTINO
string sqlIncluir = "INSERT INTO CONTARECEBER (" +
"CLIENTE," +
"VENCIMENTO," +
"DATAPAGAMENTO," + .........
") Values(" +
"\'" + "," + "\'" + ContaReceCliente + //CLIENTE
"\'" + "," + "\'" + ContaReceVencimento +// + //VENCIMENTO
"\'" + "," + "\'" + ContaRecebeDataPagto.ToString("dd.MM.yyyy")+ ........ +//DATAPAGTO
On the line where ContaRecebeDataPagto
, would have to have a if
guy se != de vazio puxar, senão colocar null
, and continue with the other information.
How can I do that?
Not directly related, but: Do not concatenate variables directly into the query, as this leaves the code vulnerable to SQL Injection attacks. Learn more by reading here: https://answall.com/q/100729/112052
– hkotsubo