Jump to content

Recommended Posts

Posted

sempre que coloco um datetimepicker da me o seguinte erro se calhar e uma coisa mm básica e não tou a ver o que é

    Dim adap As New OdbcDataAdapter("select * from customer  where createdate >= " & DateTimePicker1.Text & "", conn)

An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in System.Data.dll

Additional information: ERROR [42000] [Microsoft][ODBC SQL Server Driver]

Incorrect syntax near ','.

se eu meter as datas a mao ele funciona na perfeição e o datetimepicker já ta formatado para as minhas datas

Posted

Boas,

o .Text deve estar a retornar a data em formato extendido, visto o erro indicar a presença de uma virgula.

Experimenta substituir por algo assim:

Dim adap As New OdbcDataAdapter("select * from customer  where createdate >= " & DateTimePicker1.Value.ToShortDateString() & "", conn)
Posted

eu mando para dentro de uma textbox da seguinte forma

DateTimePicker1.Value.ToString("yyyy-MM-dd") e o resultado aparece me correcto mas quando executo na query nunca me da o resultado pretendido aparece me sempre o resultado todo e não a minha condiçao

Posted

Provavelmente a forma mais correct seria criares um odbccommand com o comando SQL e usares parametros para definir os valores.

Assim não tinhas problemas nem de formato nem de SQL Injection

Posted (edited)
Dim escolhecliente As String
	escolhecliente = "select * from customer where createdate >= @data_de_entrada"
	Dim insertcommand As New OdbcCommand(escolhecliente, conn)
	If DateTimePicker1.Checked = True Then
		insertcommand.Parameters.Add("@data_de_entrada", OdbcType.Datetime).Value = DateTimePicker1.Value
	Else
		insertcommand.Parameters.Add("@data_de_entrada", OdbcType.Datetime).Value = DBNull.Value
	End If
	adap.Fill(escolhecliente, "customer")
	DataGridView1.DataSource = ds.Tables("customer")

csgs me dar aqui uma ajuda o que tou a fazer de errado

Edited by gastao
Posted

mesmo passando dessa maneira da me sempre erro

   Dim selectCommand As String = _
    "SELECT * FROM Customer where createdate > @data_de_entrada"
    Dim adapter As OdbcDataAdapter = _
	    New OdbcDataAdapter(selectCommand, conn)
    adapter.Fill(selectCommand, "customer")
    DataGridView1.DataSource = ds.Tables("customer")
    conn.Close()
    conn.Dispose()
    conn.Close()
    adapter.InsertCommand.Parameters.Add( _
   "@data_de_entrada", OdbcType.DateTime).Value = DateTimePicker1.Value.ToString("yyyy-MM-dd")

An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

Additional information: A conversão da cadeia "SELECT * FROM Customer where cre" para o tipo 'Integer' não é válida.

Posted

Exemplo:

Using conn As New OdbcConnection("DSN=testeodbc64")
   Dim command As New OdbcCommand("select * from customer where createdate >= ?", conn)
   command.Parameters.Add("@data_de_entrada", OdbcType.DateTime).Value = DateTimePicker1.Value

   Dim adap As New OdbcDataAdapter(command)
   Dim ds As New DataSet
   adap.Fill(ds)

   MessageBox.Show(ds.Tables(0).Rows.Count)
End Using

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.