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. Database & SysAdmin
  3. Database
  4. Store Proc Problem

Store Proc Problem

Scheduled Pinned Locked Moved Database
helpdebugging
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.
  • T Offline
    T Offline
    tthellebuyck
    wrote on last edited by
    #1

    I want to use a Gridview for a standard CRUD app. So far I have my delete event wired up but I have a problem with my stored proc. I receive this error everytime i run my debugger and click the delete event. I have a catch event to catch this error. The SqlParameterCollection only accepts non-null SqlParameter type objects, not Parameter objects. Here is the code for my deleterow event. Any help is appreciated. protected void DeleteRow(object sender, GridViewDeleteEventArgs e) { try { SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConfigurationManager.ConnectionStrings["PokerTraxConnectionString"].ToString(); connection.Open(); SqlCommand delCommand = new SqlCommand(); delCommand.Connection = connection; delCommand.CommandText = "usp_Delete_Loan"; delCommand.CommandType = CommandType.StoredProcedure; delCommand.Parameters.Add(new Parameter("LoanId")); delCommand.ExecuteNonQuery(); SqlDataAdapter adapter = new SqlDataAdapter(delCommand); DataSet ds = new DataSet(); GridView1.DataSource = ds; adapter.Fill(ds); Cache["Loan"] = ds; BindPlayerNames(); connection.Close(); connection.Dispose(); delCommand.Dispose(); } catch (Exception ex) { errorMessage.Text = ex.Message; } }

    L 1 Reply Last reply
    0
    • T tthellebuyck

      I want to use a Gridview for a standard CRUD app. So far I have my delete event wired up but I have a problem with my stored proc. I receive this error everytime i run my debugger and click the delete event. I have a catch event to catch this error. The SqlParameterCollection only accepts non-null SqlParameter type objects, not Parameter objects. Here is the code for my deleterow event. Any help is appreciated. protected void DeleteRow(object sender, GridViewDeleteEventArgs e) { try { SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConfigurationManager.ConnectionStrings["PokerTraxConnectionString"].ToString(); connection.Open(); SqlCommand delCommand = new SqlCommand(); delCommand.Connection = connection; delCommand.CommandText = "usp_Delete_Loan"; delCommand.CommandType = CommandType.StoredProcedure; delCommand.Parameters.Add(new Parameter("LoanId")); delCommand.ExecuteNonQuery(); SqlDataAdapter adapter = new SqlDataAdapter(delCommand); DataSet ds = new DataSet(); GridView1.DataSource = ds; adapter.Fill(ds); Cache["Loan"] = ds; BindPlayerNames(); connection.Close(); connection.Dispose(); delCommand.Dispose(); } catch (Exception ex) { errorMessage.Text = ex.Message; } }

      L Offline
      L Offline
      Leah_Garrett
      wrote on last edited by
      #2

      This could be that the parameter was not created completey. In code that I have used I set other values for parameter object. Generic stored proc calling code:

              Dim command As New System.Data.SqlClient.SqlCommand
              command.Connection = m\_sqlConnection
      
              command.CommandText = strStoredProc
              command.CommandType = CommandType.StoredProcedure
      
              ' declare the parameter object
              Dim param As System.Data.SqlClient.SqlParameter
      
      
              Dim myEnumerator As System.Collections.IEnumerator = \_
                          parameterArray.GetEnumerator()
              Dim pItem As ParameterItem
              While myEnumerator.MoveNext()
                  pItem = CType(myEnumerator.Current, ParameterItem)
      
                  ' Add a new parameter, get back a reference to it
                  param = command.Parameters.Add(pItem.Name, pItem.Type)
      
                  ' set the parameter's direction and value
                  param.Direction = pItem.Direction
                  param.Value = pItem.Value
              End While
      
              Dim myDataAdapter As New SqlClient.SqlDataAdapter
              command.CommandTimeout = iTimeOut
              myDataAdapter.SelectCommand = command
      
              myDataAdapter.Fill(ds, "ResultSet")
      
      T 1 Reply Last reply
      0
      • L Leah_Garrett

        This could be that the parameter was not created completey. In code that I have used I set other values for parameter object. Generic stored proc calling code:

                Dim command As New System.Data.SqlClient.SqlCommand
                command.Connection = m\_sqlConnection
        
                command.CommandText = strStoredProc
                command.CommandType = CommandType.StoredProcedure
        
                ' declare the parameter object
                Dim param As System.Data.SqlClient.SqlParameter
        
        
                Dim myEnumerator As System.Collections.IEnumerator = \_
                            parameterArray.GetEnumerator()
                Dim pItem As ParameterItem
                While myEnumerator.MoveNext()
                    pItem = CType(myEnumerator.Current, ParameterItem)
        
                    ' Add a new parameter, get back a reference to it
                    param = command.Parameters.Add(pItem.Name, pItem.Type)
        
                    ' set the parameter's direction and value
                    param.Direction = pItem.Direction
                    param.Value = pItem.Value
                End While
        
                Dim myDataAdapter As New SqlClient.SqlDataAdapter
                command.CommandTimeout = iTimeOut
                myDataAdapter.SelectCommand = command
        
                myDataAdapter.Fill(ds, "ResultSet")
        
        T Offline
        T Offline
        tthellebuyck
        wrote on last edited by
        #3

        Perhaps I should have mentioned I wrote this in C#.net. Thanks for the help though I can kindve determine how this is supposed to work.

        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