Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Delete Data

Delete Data

Scheduled Pinned Locked Moved C#
questionhelp
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nishad85
    wrote on last edited by
    #1

    Hi, I want to delete data from datbase by entering a year in text box. If the there no data then i want to show "the selected date does not exist". How can i do this? pls help me? Please write code here........................

    L R 3 Replies Last reply
    0
    • N Nishad85

      Hi, I want to delete data from datbase by entering a year in text box. If the there no data then i want to show "the selected date does not exist". How can i do this? pls help me? Please write code here........................

      L Offline
      L Offline
      laddie 0
      wrote on last edited by
      #2

      It should look something like this. SqlConnection con = new SqlConnection(connecitonstring); SqlCommand cmd = new SqlCommand("delete from table where year = @year",con); cmd.Parameters.Add("@year",SqlDbType.Int).Value = int.Parse(TextBox1.Text); if(cmd.ExecuteNonQuery() > 0) { Console.WriteLine("Record deleted successfully"); } else { Console.WriteLine("No data found"); }

      1 Reply Last reply
      0
      • N Nishad85

        Hi, I want to delete data from datbase by entering a year in text box. If the there no data then i want to show "the selected date does not exist". How can i do this? pls help me? Please write code here........................

        R Offline
        R Offline
        rohitsrivastava
        wrote on last edited by
        #3

        in select statement strdelete="delete from tablename where datefield='date' objsqlconn=new sqlconnection("user id=sa;password=;data source=servername") objsqlconn.open try Dim vbmsg As String vbmsg = MessageBox.Show("Are u sure to delete this record", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Information) If vbmsg = vbYes Then strdelete = "delete from tablename where datefield='date'" objsqlcmd = New sqlcommand(strdelete, objsqlconn) objsqlcmd.executenonquery() Else MessageBox.Show("There is no field exits") End If catch (ex as exception) exception(ex.message) end try

        1 Reply Last reply
        0
        • N Nishad85

          Hi, I want to delete data from datbase by entering a year in text box. If the there no data then i want to show "the selected date does not exist". How can i do this? pls help me? Please write code here........................

          R Offline
          R Offline
          rohitsrivastava
          wrote on last edited by
          #4

          yes

          C 1 Reply Last reply
          0
          • R rohitsrivastava

            yes

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            rohitsrivastava wrote:

            yes

            :confused:


            Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

            D 1 Reply Last reply
            0
            • C Colin Angus Mackay

              rohitsrivastava wrote:

              yes

              :confused:


              Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Why do I get the feeling the OP is going to copy'n'paste the code thrown at him and wonder why it doesn't work?

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups