Solved

vb.net deleteing form sql db???

Posted on 2011-09-02
5
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 total points
ID: 36472748
           cmd.CommandText = "Delete from Holidays where ""Date""=@date and UserName = @myname"

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

635 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