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. deleting sqlserver table data with delete command using DataAdapter in c#

deleting sqlserver table data with delete command using DataAdapter in c#

Scheduled Pinned Locked Moved C#
questioncsharpdatabasesql-serversysadmin
3 Posts 2 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
    Nishanth mahe
    wrote on last edited by
    #1

    Hi, I am trying to insert/update/delete a field from sql server table using dataadapter in c# windows application. Here insert and update are happening,but 'delete' is not working I will show my delete part : public int UpdateAllUserDetails(DataSet dsUsers) { private SqlConnection connection; private SqlCommand command; private SqlDataAdapter dataAdapter; connection = new SqlConnection(ConfigurationManager.AppSettings.Get("conString")); connection.Open(); dataAdapter = new SqlDataAdapter(command); dataAdapter.DeleteCommand = new SqlCommand("DELETE FROM UserDetails WHERE vUserName=@vUserName", connection); dataAdapter.DeleteCommand.Parameters.Add("@vUserName", SqlDbType.VarChar, 50, "vUserName"); int ret = dataAdapter.Update(dsUsers); return ret; } can somebody say what is missing here?

    K 1 Reply Last reply
    0
    • N Nishanth mahe

      Hi, I am trying to insert/update/delete a field from sql server table using dataadapter in c# windows application. Here insert and update are happening,but 'delete' is not working I will show my delete part : public int UpdateAllUserDetails(DataSet dsUsers) { private SqlConnection connection; private SqlCommand command; private SqlDataAdapter dataAdapter; connection = new SqlConnection(ConfigurationManager.AppSettings.Get("conString")); connection.Open(); dataAdapter = new SqlDataAdapter(command); dataAdapter.DeleteCommand = new SqlCommand("DELETE FROM UserDetails WHERE vUserName=@vUserName", connection); dataAdapter.DeleteCommand.Parameters.Add("@vUserName", SqlDbType.VarChar, 50, "vUserName"); int ret = dataAdapter.Update(dsUsers); return ret; } can somebody say what is missing here?

      K Offline
      K Offline
      kstls
      wrote on last edited by
      #2

      Try and run the same sql statement in your DBMS as it will tell you what if anything is wrong with your statement. My guess is that you may have some dependencies in your tables, that prevent you from deleting.

      N 1 Reply Last reply
      0
      • K kstls

        Try and run the same sql statement in your DBMS as it will tell you what if anything is wrong with your statement. My guess is that you may have some dependencies in your tables, that prevent you from deleting.

        N Offline
        N Offline
        Nishanth mahe
        wrote on last edited by
        #3

        Thanks kstls, But I have no dependencies for this because i am trying to delete some newly inserted userdetails data, which will create a new field in that single table only and not in any of the dependency tables. Here by debugging the code i am getting the update command as : "DELETE FROM UserDetails WHERE vUserName=@vUserName" which when run directly in DBMS just replacing vUserName as 'testuser' which is the primarykey vUserName : [ DELETE FROM UserDetails WHERE vUserName='testuser' ] is deleting properly But not working from code

        modified on Tuesday, November 17, 2009 6:48 AM

        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