set value of SqlDataSource parameter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roger Jordan

    set value of SqlDataSource parameter

    Hello,

    I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
    has a parameter, with isdefined in SqlDataSource.D eleteParameter:

    DELETE FROM [testTable] WHERE [ID]=@ID

    The parameter is not bind to any control, cookie or something like this.
    How do I set a value for this parameter before calling the
    SQLDataSource1. Delete() method?

    As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
    SqlParameter) there is no "value" property.

    I like to use it in a for ()-Statement to delete a number of elements, so i
    each step I want to set the parameter and then call the delete() method.

    I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.

    Thanks for you help
    Roger




  • =?Utf-8?B?anAybXNmdA==?=

    #2
    RE: set value of SqlDataSource parameter

    Are you sure, Roger? I'm not able to find anything called SQLDataSource.

    That being said:

    using System.Data.Sql Client;

    private void Scratch(string dbConn) {
    string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
    SqlConnection con = new SqlConnection(d bConn);
    SqlCommand cmd = new SqlCommand(sqlD el, con);
    cmd.Parameters. Add("@ID", SqlDbType.VarCh ar, 8).Value = "123";
    // now do what you want with it.
    }


    "Roger Jordan" wrote:
    Hello,
    >
    I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
    has a parameter, with isdefined in SqlDataSource.D eleteParameter:
    >
    DELETE FROM [testTable] WHERE [ID]=@ID
    >
    The parameter is not bind to any control, cookie or something like this.
    How do I set a value for this parameter before calling the
    SQLDataSource1. Delete() method?
    >
    As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
    SqlParameter) there is no "value" property.
    >
    I like to use it in a for ()-Statement to delete a number of elements, so i
    each step I want to set the parameter and then call the delete() method.
    >
    I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.
    >
    Thanks for you help
    Roger
    >
    >
    >
    >
    >

    Comment

    • Roger Jordan

      #3
      Re: set value of SqlDataSource parameter

      Yes, I'm sure.
      It's a System.Web.UI.W ebControls.SqlD ataSource
      This component could be bind to a grid (thats the case in my appliction) or
      any other data sensitive control. But addionally I want to manual call the
      delete method.


      "jp2msft" <jp2msft@discus sions.microsoft .comschrieb im Newsbeitrag
      news:FA4910FB-1A38-4B30-8A86-3EEB0338E803@mi crosoft.com...
      Are you sure, Roger? I'm not able to find anything called SQLDataSource.
      >
      That being said:
      >
      using System.Data.Sql Client;
      >
      private void Scratch(string dbConn) {
      string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
      SqlConnection con = new SqlConnection(d bConn);
      SqlCommand cmd = new SqlCommand(sqlD el, con);
      cmd.Parameters. Add("@ID", SqlDbType.VarCh ar, 8).Value = "123";
      // now do what you want with it.
      }
      >
      >
      "Roger Jordan" wrote:
      >
      >Hello,
      >>
      >I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
      >has a parameter, with isdefined in SqlDataSource.D eleteParameter:
      >>
      >DELETE FROM [testTable] WHERE [ID]=@ID
      >>
      >The parameter is not bind to any control, cookie or something like this.
      >How do I set a value for this parameter before calling the
      >SQLDataSource1 .Delete() method?
      >>
      >As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
      >SqlParameter ) there is no "value" property.
      >>
      >I like to use it in a for ()-Statement to delete a number of elements, so
      >i
      >each step I want to set the parameter and then call the delete() method.
      >>
      >I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.
      >>
      >Thanks for you help
      >Roger
      >>
      >>
      >>
      >>
      >>

      Comment

      • =?Utf-8?B?anAybXNmdA==?=

        #4
        Re: set value of SqlDataSource parameter

        That explains a lot! I don't use web controls.

        So, did my solution guide you along your way? Obviously, you would have to
        taylor it to a web control, but you get the idea, right?

        "Roger Jordan" wrote:
        Yes, I'm sure.
        It's a System.Web.UI.W ebControls.SqlD ataSource
        This component could be bind to a grid (thats the case in my appliction) or
        any other data sensitive control. But addionally I want to manual call the
        delete method.
        >
        >
        "jp2msft" <jp2msft@discus sions.microsoft .comschrieb im Newsbeitrag
        news:FA4910FB-1A38-4B30-8A86-3EEB0338E803@mi crosoft.com...
        Are you sure, Roger? I'm not able to find anything called SQLDataSource.

        That being said:

        using System.Data.Sql Client;

        private void Scratch(string dbConn) {
        string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
        SqlConnection con = new SqlConnection(d bConn);
        SqlCommand cmd = new SqlCommand(sqlD el, con);
        cmd.Parameters. Add("@ID", SqlDbType.VarCh ar, 8).Value = "123";
        // now do what you want with it.
        }


        "Roger Jordan" wrote:
        Hello,
        >
        I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
        has a parameter, with isdefined in SqlDataSource.D eleteParameter:
        >
        DELETE FROM [testTable] WHERE [ID]=@ID
        >
        The parameter is not bind to any control, cookie or something like this.
        How do I set a value for this parameter before calling the
        SQLDataSource1. Delete() method?
        >
        As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
        SqlParameter) there is no "value" property.
        >
        I like to use it in a for ()-Statement to delete a number of elements, so
        i
        each step I want to set the parameter and then call the delete() method.
        >
        I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.
        >
        Thanks for you help
        Roger
        >
        >
        >
        >
        >
        >
        >
        >

        Comment

        Working...