Lo hice sin utilizar objetos y funcionó y cuando quise implementarlo de esta manera ya no anduvo.
El error que me dice es:
Cita:
Intenté cambiar los tipos de datos, usar CInt antes de asignar el valor, y sin embargo, nada pasa.Conversion from string "insert into turnos values('11/4/" to type 'Double' is not valid.
La base de datos tiene los mismos campos que la clase turno, y los mismos tipos.
Acá pasteo la clase:
Cita:
Y así creo el objeto y le paso los parámetros...Public Class turno
Public dia As Date
Public hppio As Integer
Public hfin As Integer
Public paciente As Integer
Public profesional As Integer
Public total As Integer
Public adelanto As Integer
Public resto As Integer
Public Sub agendar()
Dim conexion As New SqlClient.SqlConnection
Dim comando As New SqlClient.SqlCommand
conexion.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\David\My Documents\Visual Studio 2005\Projects\Turnos\Turnos\mibase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Try
conexion.Open()
Catch ex As Exception
MsgBox("No se ha podido conectar a la base de datos!", MsgBoxStyle.Critical, "Error!")
Return
End Try
comando.CommandType = CommandType.Text
comando.CommandText = "insert into turnos values('" + dia + "'," + hppio + "," + hfin + "," + paciente + "," + _
profesional + "," + total + "," + adelanto + "," + resto + ")"
comando.Connection = conexion
If hppio <> "" And hfin <> "" And paciente <> "" And profesional <> "" Then
Try
comando.ExecuteNonQuery()
Catch ex As Exception
MsgBox("No se ha podido agregar el turno!", MsgBoxStyle.Critical, "Error!")
conexion.Close()
Return
End Try
Else
MsgBox("Debe completar los datos requeridos!", MsgBoxStyle.Critical, "Error!")
End If
conexion.Close()
End Sub
End Class
Public dia As Date
Public hppio As Integer
Public hfin As Integer
Public paciente As Integer
Public profesional As Integer
Public total As Integer
Public adelanto As Integer
Public resto As Integer
Public Sub agendar()
Dim conexion As New SqlClient.SqlConnection
Dim comando As New SqlClient.SqlCommand
conexion.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\David\My Documents\Visual Studio 2005\Projects\Turnos\Turnos\mibase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Try
conexion.Open()
Catch ex As Exception
MsgBox("No se ha podido conectar a la base de datos!", MsgBoxStyle.Critical, "Error!")
Return
End Try
comando.CommandType = CommandType.Text
comando.CommandText = "insert into turnos values('" + dia + "'," + hppio + "," + hfin + "," + paciente + "," + _
profesional + "," + total + "," + adelanto + "," + resto + ")"
comando.Connection = conexion
If hppio <> "" And hfin <> "" And paciente <> "" And profesional <> "" Then
Try
comando.ExecuteNonQuery()
Catch ex As Exception
MsgBox("No se ha podido agregar el turno!", MsgBoxStyle.Critical, "Error!")
conexion.Close()
Return
End Try
Else
MsgBox("Debe completar los datos requeridos!", MsgBoxStyle.Critical, "Error!")
End If
conexion.Close()
End Sub
End Class
Cita:
Alguna sugerencia? Dim nuevoturno As New turno
With nuevoturno
.dia = DateTimePicker1.Value
.hppio = TextBox1.Text
.hfin = TextBox2.Text
.paciente = ComboBox1.Text
.profesional = ComboBox2.Text
.total = TextBox3.Text
.adelanto = TextBox4.Text
.resto = nuevoturno.total - nuevoturno.adelanto
End With
nuevoturno.agendar()
With nuevoturno
.dia = DateTimePicker1.Value
.hppio = TextBox1.Text
.hfin = TextBox2.Text
.paciente = ComboBox1.Text
.profesional = ComboBox2.Text
.total = TextBox3.Text
.adelanto = TextBox4.Text
.resto = nuevoturno.total - nuevoturno.adelanto
End With
nuevoturno.agendar()