Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

vb.net deleteing form sql db???

How would i correct this code so it will delete form my db?

Shared Function deleteit(ByVal thedate As DateTime, ByVal myname As String) As Integer
        Dim con As New SqlConnection(local)
        Dim cmd As New SqlCommand
        cmd.Connection = con
        Try
            con.Open()
            Dim theres As Integer
            cmd.Parameters.AddWithValue("@date", thedate)
            cmd.Parameters.AddWithValue("@myname", myname)
            cmd.CommandText = "Delete * from Holidays where Date=@date and UserName = @myname"
            theres = cmd.ExecuteScalar()
            Return theres
        Catch ex As Exception
            Throw ex
        Finally
            con.Close()
        End Try
    End Function

Open in new window

Avatar of Limbeck
Limbeck

how about

          cmd.CommandText = "Delete from Holidays where Date=@date and UserName = @myname"
 
not sure about your coolumnname date though. its a reserved word, can you change it?

            cmd.CommandText = "Delete from Holidays where 'Date'=@date and UserName = @myname"
Avatar of Member_2_5230414

ASKER

i now get

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting datetime from character string.
jus to note i convetrted it here        dateallreadybooked.deleteit(DateTime.Parse(result.Split("|")(1)), "Jarratt")
ASKER CERTIFIED SOLUTION
Avatar of Limbeck
Limbeck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial