Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb.net deleteing form sql db???

Posted on 2011-09-02
5
Medium Priority
?
278 Views
Last Modified: 2012-05-12
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
Comment
Question by:runnerjp2005
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Limbeck
ID: 36472698
how about

          cmd.CommandText = "Delete from Holidays where Date=@date and UserName = @myname"
 
0
 
LVL 19

Expert Comment

by:Limbeck
ID: 36472702
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
 

Author Comment

by:runnerjp2005
ID: 36472709
i now get

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting datetime from character string.
0
 

Author Comment

by:runnerjp2005
ID: 36472731
jus to note i convetrted it here        dateallreadybooked.deleteit(DateTime.Parse(result.Split("|")(1)), "Jarratt")
0
 
LVL 19

Accepted Solution

by:
Limbeck earned 2000 total points
ID: 36472748
           cmd.CommandText = "Delete from Holidays where ""Date""=@date and UserName = @myname"

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question