Not null date records

edusoft

Member
Joined
Mar 17, 2011
Messages
6
Programming Experience
Beginner
Hello, my project does not record the date it was filled with a blank. Help me, please. Use VB 2008 e BD Access.

The project goes here:
projetovb2008_bdaccess.zip - 4shared.com - online file sharing and storage - download

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim MyConnection As OleDbConnection
        Dim sql_checkDATA As String
        If DatanascimentoMaskedTextBox.Text = "  /  /" Then
            'BancodedadosDataSet.EnforceConstraints = False
            sql_checkDATA = "''"   'Já tentei como Null
        Else
            sql_checkDATA = "#" & DatanascimentoMaskedTextBox.Text & "#"
        End If
        Try
            MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Application.StartupPath + "\bancodedados.mdb")
            Dim Sql As String = "UPDATE cadastro SET codigo=" & CodigoTextBox.Text & ", nome='" & NomeTextBox.Text & "', salario ='" & SalarioTextBox.Text & "', datanascimento=" & sql_checkDATA & " WHERE codigo=" & CodigoTextBox.Text & ""
            MyConnection.Open()
            Dim MyComand As New OleDbCommand(Sql, MyConnection)
            MyComand.ExecuteNonQuery()
            MessageBox.Show("Gravado com sucesso!!!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            MyConnection.Close()
            MyComand.Dispose()
            MyConnection.Dispose()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
 
Last edited:
Never use string concatenation to build SQL statements. Always use parameters. Follow the Blog link in my signature and check out my post on ADO.NET Parameters for more info.
 
The code above was only a test. Data Adapter update this. Because it does not accept null record date, instead of a date already exists?
 
Please, where I insert DBNull.Value? Thanks Eduardo

UPDATE `cadastro` SET `codigo` = ?, `nome` = ?, `salario` = ?, `datanascimento` = ? WHERE ((`codigo` = ?) AND ((? = 1 AND `nome` IS NULL) OR (`nome` = ?)) AND ((? = 1 AND `salario` IS NULL) OR (`salario` = ?)) AND ((? = 1 AND `datanascimento` IS NULL) OR (`datanascimento` = ?)))

imgxsd.jpg
 
Now you've changed things completely. You're using a typed DataSet now so your code will be quite different to what it was before. Now you don't use DBNull at all, because that's handled for you internally. Is the data stored in a DataTable now or are you passing the field values directly to a method called on a TableAdapter?
 
Instead of those enormous screenshots, maybe you could have just answered my question. If the data is in a DataTable then you are setting the fields of a DataRow. Each field is NULL by default so you don't actually have to do anything. To set a field to NULL explicitly, call the SetXYZNull method on the DataRow, where XYZ is the name of your column.
 
Back
Top