Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

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

0
runnerjp2005
Asked:
runnerjp2005
  • 3
  • 2
1 Solution
 
LimbeckCommented:
how about

          cmd.CommandText = "Delete from Holidays where Date=@date and UserName = @myname"
 
0
 
LimbeckCommented:
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"
0
 
runnerjp2005Author Commented:
i now get

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting datetime from character string.
0
 
runnerjp2005Author Commented:
jus to note i convetrted it here        dateallreadybooked.deleteit(DateTime.Parse(result.Split("|")(1)), "Jarratt")
0
 
LimbeckCommented:
           cmd.CommandText = "Delete from Holidays where ""Date""=@date and UserName = @myname"

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now