Arrrrg !!!! ObjectDataSource Issues

Discussion in 'ASP .Net' started by WertmanTheMad, Oct 8, 2004.

  1. I am having some serious problems with the ObjectDatSource in .Net 2.0

    I can select as a dataset, I can update , I cannot for my LIFE Delete
    a record !

    It keeps saying "Prepared statement '(@au_id nvarchar(4000))DELETE
    FROM [authors] WHERE [au_id] = @au' expects parameter @au_id, which
    was not supplied. " HorseCRAP ! I am supplying it jUST FRIGGIN PERFECT
    for the update statement !

    Here is ALL the code, first the UPDATE function from the AuthorsDB
    class, which works perfect, Then the Delete that FAILS ????

    Shared Function UpdateAuthors(ByVal au_id As String, ByVal
    au_lname As String, ByVal au_fname As String, ByVal state As String)
    As Integer
    Dim connectionString As String =
    ConfigurationSettings.ConnectionStrings("Pubs").ConnectionString

    Dim dbConnection As System.Data.IDbConnection = New
    System.Data.SqlClient.SqlConnection(connectionString)

    Dim queryString As String = "UPDATE [authors] SET
    [au_lname]=@au_lname, [au_fname]=@au_fname, [state]=@state W" & _
    "HERE ([authors].[au_id] = @au_id)"
    Dim dbCommand As System.Data.IDbCommand = New
    System.Data.SqlClient.SqlCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection

    Dim dbParam_au_id As System.Data.IDataParameter = New
    System.Data.SqlClient.SqlParameter
    dbParam_au_id.ParameterName = "@au_id"
    dbParam_au_id.Value = au_id
    dbParam_au_id.DbType = System.Data.DbType.[String]
    dbCommand.Parameters.Add(dbParam_au_id)
    Dim dbParam_au_lname As System.Data.IDataParameter = New
    System.Data.SqlClient.SqlParameter
    dbParam_au_lname.ParameterName = "@au_lname"
    dbParam_au_lname.Value = au_lname
    dbParam_au_lname.DbType = System.Data.DbType.[String]
    dbCommand.Parameters.Add(dbParam_au_lname)
    Dim dbParam_au_fname As System.Data.IDataParameter = New
    System.Data.SqlClient.SqlParameter
    dbParam_au_fname.ParameterName = "@au_fname"
    dbParam_au_fname.Value = au_fname
    dbParam_au_fname.DbType = System.Data.DbType.[String]
    dbCommand.Parameters.Add(dbParam_au_fname)
    Dim dbParam_state As System.Data.IDataParameter = New
    System.Data.SqlClient.SqlParameter
    dbParam_state.ParameterName = "@state"
    dbParam_state.Value = state
    dbParam_state.DbType = System.Data.DbType.StringFixedLength
    dbCommand.Parameters.Add(dbParam_state)

    Dim rowsAffected As Integer = 0
    dbConnection.Open()
    Try
    rowsAffected = dbCommand.ExecuteNonQuery
    Finally
    dbConnection.Close()
    End Try

    Return rowsAffected
    End Function

    Shared Function DeleteAuthors(ByVal au_id As String) As Integer
    Dim connectionString As String =
    ConfigurationSettings.ConnectionStrings("Pubs").ConnectionString

    Dim dbConnection As System.Data.IDbConnection = New
    System.Data.SqlClient.SqlConnection(connectionString)

    Dim queryString As String = "DELETE FROM [authors] WHERE
    [au_id] = @au_id"


    Dim dbCommand As System.Data.IDbCommand = New
    System.Data.SqlClient.SqlCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection


    Dim dbParam_au_id As System.Data.IDataParameter = New
    System.Data.SqlClient.SqlParameter
    dbParam_au_id.ParameterName = "@au_id"
    dbParam_au_id.Value = au_id
    dbParam_au_id.DbType = System.Data.DbType.[String]
    dbCommand.Parameters.Add(dbParam_au_id)

    Dim rowsAffected As Integer = 0
    dbConnection.Open()
    Try
    rowsAffected = dbCommand.ExecuteNonQuery

    Finally
    dbConnection.Close()
    End Try

    Return rowsAffected
    End Function

    End Class


    AND Here is the Code from the ASPX page

    <asp:GridView ID="GridView1" Runat="server"
    DataSourceID="ObjectDataSource1"
    AllowPaging="True" AllowSorting="True">
    <Columns>
    <asp:CommandField ShowDeleteButton="True"
    ShowEditButton="True" ShowSelectButton="True"></asp:CommandField>
    </Columns>
    </asp:GridView>
    <br />
    &nbsp;<asp:ObjectDataSource ID="ObjectDataSource1"
    Runat="server" TypeName="AuthorsDB"
    SelectMethod="SelectAuthors" UpdateMethod="UpdateAuthors"
    DeleteMethod="DeleteAuthors" OldValuesParameterFormatString="{0}">
    <DeleteParameters>
    <asp:parameter Type="String"
    Name="au_id"></asp:parameter>
    </DeleteParameters>
    <UpdateParameters>
    <asp:parameter Type="String"
    Name="au_id"></asp:parameter>
    <asp:parameter Type="String"
    Name="au_lname"></asp:parameter>
    <asp:parameter Type="String"
    Name="au_fname"></asp:parameter>
    <asp:parameter Type="String"
    Name="state"></asp:parameter>
    </UpdateParameters>
    </asp:ObjectDataSource>

    NOW here is where it gets confusing to me , if I change
    dbParam_au_id.Value = au_id
    to
    dbParam_au_id.Value = "12344-234-2255"
    and hard code the value it WORKS !

    I have tried every possible combination of values and the thing claims
    it the value isnt supplied, I tired it with and without the original_
    (And tried many combinations in the paramater code.

    Can someone please explain what I am doing wrong ?

    The MS Sample has update and select methods but no friggin delete, the
    only thing I can think is they coulnt get it to work right either.


    I would greatly appreciate some help if anyone else has a clue

    Chris
    WertmanTheMad, Oct 8, 2004
    #1
    1. Advertising

  2. Post the link..!


    "WertmanTheMad" wrote:

    > I am having some serious problems with the ObjectDatSource in .Net 2.0
    >
    > I can select as a dataset, I can update , I cannot for my LIFE Delete
    > a record !
    >
    > It keeps saying "Prepared statement '(@au_id nvarchar(4000))DELETE
    > FROM [authors] WHERE [au_id] = @au' expects parameter @au_id, which
    > was not supplied. " HorseCRAP ! I am supplying it jUST FRIGGIN PERFECT
    > for the update statement !
    >
    > Here is ALL the code, first the UPDATE function from the AuthorsDB
    > class, which works perfect, Then the Delete that FAILS ????
    >
    > Shared Function UpdateAuthors(ByVal au_id As String, ByVal
    > au_lname As String, ByVal au_fname As String, ByVal state As String)
    > As Integer
    > Dim connectionString As String =
    > ConfigurationSettings.ConnectionStrings("Pubs").ConnectionString
    >
    > Dim dbConnection As System.Data.IDbConnection = New
    > System.Data.SqlClient.SqlConnection(connectionString)
    >
    > Dim queryString As String = "UPDATE [authors] SET
    > [au_lname]=@au_lname, [au_fname]=@au_fname, [state]=@state W" & _
    > "HERE ([authors].[au_id] = @au_id)"
    > Dim dbCommand As System.Data.IDbCommand = New
    > System.Data.SqlClient.SqlCommand
    > dbCommand.CommandText = queryString
    > dbCommand.Connection = dbConnection
    >
    > Dim dbParam_au_id As System.Data.IDataParameter = New
    > System.Data.SqlClient.SqlParameter
    > dbParam_au_id.ParameterName = "@au_id"
    > dbParam_au_id.Value = au_id
    > dbParam_au_id.DbType = System.Data.DbType.[String]
    > dbCommand.Parameters.Add(dbParam_au_id)
    > Dim dbParam_au_lname As System.Data.IDataParameter = New
    > System.Data.SqlClient.SqlParameter
    > dbParam_au_lname.ParameterName = "@au_lname"
    > dbParam_au_lname.Value = au_lname
    > dbParam_au_lname.DbType = System.Data.DbType.[String]
    > dbCommand.Parameters.Add(dbParam_au_lname)
    > Dim dbParam_au_fname As System.Data.IDataParameter = New
    > System.Data.SqlClient.SqlParameter
    > dbParam_au_fname.ParameterName = "@au_fname"
    > dbParam_au_fname.Value = au_fname
    > dbParam_au_fname.DbType = System.Data.DbType.[String]
    > dbCommand.Parameters.Add(dbParam_au_fname)
    > Dim dbParam_state As System.Data.IDataParameter = New
    > System.Data.SqlClient.SqlParameter
    > dbParam_state.ParameterName = "@state"
    > dbParam_state.Value = state
    > dbParam_state.DbType = System.Data.DbType.StringFixedLength
    > dbCommand.Parameters.Add(dbParam_state)
    >
    > Dim rowsAffected As Integer = 0
    > dbConnection.Open()
    > Try
    > rowsAffected = dbCommand.ExecuteNonQuery
    > Finally
    > dbConnection.Close()
    > End Try
    >
    > Return rowsAffected
    > End Function
    >
    > Shared Function DeleteAuthors(ByVal au_id As String) As Integer
    > Dim connectionString As String =
    > ConfigurationSettings.ConnectionStrings("Pubs").ConnectionString
    >
    > Dim dbConnection As System.Data.IDbConnection = New
    > System.Data.SqlClient.SqlConnection(connectionString)
    >
    > Dim queryString As String = "DELETE FROM [authors] WHERE
    > [au_id] = @au_id"
    >
    >
    > Dim dbCommand As System.Data.IDbCommand = New
    > System.Data.SqlClient.SqlCommand
    > dbCommand.CommandText = queryString
    > dbCommand.Connection = dbConnection
    >
    >
    > Dim dbParam_au_id As System.Data.IDataParameter = New
    > System.Data.SqlClient.SqlParameter
    > dbParam_au_id.ParameterName = "@au_id"
    > dbParam_au_id.Value = au_id
    > dbParam_au_id.DbType = System.Data.DbType.[String]
    > dbCommand.Parameters.Add(dbParam_au_id)
    >
    > Dim rowsAffected As Integer = 0
    > dbConnection.Open()
    > Try
    > rowsAffected = dbCommand.ExecuteNonQuery
    >
    > Finally
    > dbConnection.Close()
    > End Try
    >
    > Return rowsAffected
    > End Function
    >
    > End Class
    >
    >
    > AND Here is the Code from the ASPX page
    >
    > <asp:GridView ID="GridView1" Runat="server"
    > DataSourceID="ObjectDataSource1"
    > AllowPaging="True" AllowSorting="True">
    > <Columns>
    > <asp:CommandField ShowDeleteButton="True"
    > ShowEditButton="True" ShowSelectButton="True"></asp:CommandField>
    > </Columns>
    > </asp:GridView>
    > <br />
    > <asp:ObjectDataSource ID="ObjectDataSource1"
    > Runat="server" TypeName="AuthorsDB"
    > SelectMethod="SelectAuthors" UpdateMethod="UpdateAuthors"
    > DeleteMethod="DeleteAuthors" OldValuesParameterFormatString="{0}">
    > <DeleteParameters>
    > <asp:parameter Type="String"
    > Name="au_id"></asp:parameter>
    > </DeleteParameters>
    > <UpdateParameters>
    > <asp:parameter Type="String"
    > Name="au_id"></asp:parameter>
    > <asp:parameter Type="String"
    > Name="au_lname"></asp:parameter>
    > <asp:parameter Type="String"
    > Name="au_fname"></asp:parameter>
    > <asp:parameter Type="String"
    > Name="state"></asp:parameter>
    > </UpdateParameters>
    > </asp:ObjectDataSource>
    >
    > NOW here is where it gets confusing to me , if I change
    > dbParam_au_id.Value = au_id
    > to
    > dbParam_au_id.Value = "12344-234-2255"
    > and hard code the value it WORKS !
    >
    > I have tried every possible combination of values and the thing claims
    > it the value isnt supplied, I tired it with and without the original_
    > (And tried many combinations in the paramater code.
    >
    > Can someone please explain what I am doing wrong ?
    >
    > The MS Sample has update and select methods but no friggin delete, the
    > only thing I can think is they coulnt get it to work right either.
    >
    >
    > I would greatly appreciate some help if anyone else has a clue
    >
    > Chris
    >
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 8, 2004
    #2
    1. Advertising

  3. The link to WHAT ?

    > Post the link..!


    MY code is below the MSDN Example does NOT have a delete method.




    > "WertmanTheMad" wrote:
    >
    > > I am having some serious problems with the ObjectDatSource in .Net 2.0
    > >
    > > I can select as a dataset, I can update , I cannot for my LIFE Delete
    > > a record !
    > >
    > > It keeps saying "Prepared statement '(@au_id nvarchar(4000))DELETE
    > > FROM [authors] WHERE [au_id] = @au' expects parameter @au_id, which
    > > was not supplied. " HorseCRAP ! I am supplying it jUST FRIGGIN PERFECT
    > > for the update statement !
    > >
    > > Here is ALL the code, first the UPDATE function from the AuthorsDB
    > > class, which works perfect, Then the Delete that FAILS ????
    > >
    > > Shared Function UpdateAuthors(ByVal au_id As String, ByVal
    > > au_lname As String, ByVal au_fname As String, ByVal state As String)
    > > As Integer
    > > Dim connectionString As String =
    > > ConfigurationSettings.ConnectionStrings("Pubs").ConnectionString
    > >
    > > Dim dbConnection As System.Data.IDbConnection = New
    > > System.Data.SqlClient.SqlConnection(connectionString)
    > >
    > > Dim queryString As String = "UPDATE [authors] SET
    > > [au_lname]=@au_lname, [au_fname]=@au_fname, [state]=@state W" & _
    > > "HERE ([authors].[au_id] = @au_id)"
    > > Dim dbCommand As System.Data.IDbCommand = New
    > > System.Data.SqlClient.SqlCommand
    > > dbCommand.CommandText = queryString
    > > dbCommand.Connection = dbConnection
    > >
    > > Dim dbParam_au_id As System.Data.IDataParameter = New
    > > System.Data.SqlClient.SqlParameter
    > > dbParam_au_id.ParameterName = "@au_id"
    > > dbParam_au_id.Value = au_id
    > > dbParam_au_id.DbType = System.Data.DbType.[String]
    > > dbCommand.Parameters.Add(dbParam_au_id)
    > > Dim dbParam_au_lname As System.Data.IDataParameter = New
    > > System.Data.SqlClient.SqlParameter
    > > dbParam_au_lname.ParameterName = "@au_lname"
    > > dbParam_au_lname.Value = au_lname
    > > dbParam_au_lname.DbType = System.Data.DbType.[String]
    > > dbCommand.Parameters.Add(dbParam_au_lname)
    > > Dim dbParam_au_fname As System.Data.IDataParameter = New
    > > System.Data.SqlClient.SqlParameter
    > > dbParam_au_fname.ParameterName = "@au_fname"
    > > dbParam_au_fname.Value = au_fname
    > > dbParam_au_fname.DbType = System.Data.DbType.[String]
    > > dbCommand.Parameters.Add(dbParam_au_fname)
    > > Dim dbParam_state As System.Data.IDataParameter = New
    > > System.Data.SqlClient.SqlParameter
    > > dbParam_state.ParameterName = "@state"
    > > dbParam_state.Value = state
    > > dbParam_state.DbType = System.Data.DbType.StringFixedLength
    > > dbCommand.Parameters.Add(dbParam_state)
    > >
    > > Dim rowsAffected As Integer = 0
    > > dbConnection.Open()
    > > Try
    > > rowsAffected = dbCommand.ExecuteNonQuery
    > > Finally
    > > dbConnection.Close()
    > > End Try
    > >
    > > Return rowsAffected
    > > End Function
    > >
    > > Shared Function DeleteAuthors(ByVal au_id As String) As Integer
    > > Dim connectionString As String =
    > > ConfigurationSettings.ConnectionStrings("Pubs").ConnectionString
    > >
    > > Dim dbConnection As System.Data.IDbConnection = New
    > > System.Data.SqlClient.SqlConnection(connectionString)
    > >
    > > Dim queryString As String = "DELETE FROM [authors] WHERE
    > > [au_id] = @au_id"
    > >
    > >
    > > Dim dbCommand As System.Data.IDbCommand = New
    > > System.Data.SqlClient.SqlCommand
    > > dbCommand.CommandText = queryString
    > > dbCommand.Connection = dbConnection
    > >
    > >
    > > Dim dbParam_au_id As System.Data.IDataParameter = New
    > > System.Data.SqlClient.SqlParameter
    > > dbParam_au_id.ParameterName = "@au_id"
    > > dbParam_au_id.Value = au_id
    > > dbParam_au_id.DbType = System.Data.DbType.[String]
    > > dbCommand.Parameters.Add(dbParam_au_id)
    > >
    > > Dim rowsAffected As Integer = 0
    > > dbConnection.Open()
    > > Try
    > > rowsAffected = dbCommand.ExecuteNonQuery
    > >
    > > Finally
    > > dbConnection.Close()
    > > End Try
    > >
    > > Return rowsAffected
    > > End Function
    > >
    > > End Class
    > >
    > >
    > > AND Here is the Code from the ASPX page
    > >
    > > <asp:GridView ID="GridView1" Runat="server"
    > > DataSourceID="ObjectDataSource1"
    > > AllowPaging="True" AllowSorting="True">
    > > <Columns>
    > > <asp:CommandField ShowDeleteButton="True"
    > > ShowEditButton="True" ShowSelectButton="True"></asp:CommandField>
    > > </Columns>
    > > </asp:GridView>
    > > <br />
    > > <asp:ObjectDataSource ID="ObjectDataSource1"
    > > Runat="server" TypeName="AuthorsDB"
    > > SelectMethod="SelectAuthors" UpdateMethod="UpdateAuthors"
    > > DeleteMethod="DeleteAuthors" OldValuesParameterFormatString="{0}">
    > > <DeleteParameters>
    > > <asp:parameter Type="String"
    > > Name="au_id"></asp:parameter>
    > > </DeleteParameters>
    > > <UpdateParameters>
    > > <asp:parameter Type="String"
    > > Name="au_id"></asp:parameter>
    > > <asp:parameter Type="String"
    > > Name="au_lname"></asp:parameter>
    > > <asp:parameter Type="String"
    > > Name="au_fname"></asp:parameter>
    > > <asp:parameter Type="String"
    > > Name="state"></asp:parameter>
    > > </UpdateParameters>
    > > </asp:ObjectDataSource>
    > >
    > > NOW here is where it gets confusing to me , if I change
    > > dbParam_au_id.Value = au_id
    > > to
    > > dbParam_au_id.Value = "12344-234-2255"
    > > and hard code the value it WORKS !
    > >
    > > I have tried every possible combination of values and the thing claims
    > > it the value isnt supplied, I tired it with and without the original_
    > > (And tried many combinations in the paramater code.
    > >
    > > Can someone please explain what I am doing wrong ?
    > >
    > > The MS Sample has update and select methods but no friggin delete, the
    > > only thing I can think is they coulnt get it to work right either.
    > >
    > >
    > > I would greatly appreciate some help if anyone else has a clue
    > >
    > > Chris
    > >
    WertmanTheMad, Oct 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. WertmanTheMad

    objectDataSource

    WertmanTheMad, Sep 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    347
    WertmanTheMad
    Sep 15, 2004
  2. =?Utf-8?B?RG9u?=

    ObjectDataSource

    =?Utf-8?B?RG9u?=, Nov 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    403
    =?Utf-8?B?RG9u?=
    Nov 22, 2004
  3. =?Utf-8?B?cm9zczYxMw==?=

    Issues with Stongly-Typed ObjectDataSource's UpdateMethod

    =?Utf-8?B?cm9zczYxMw==?=, Mar 6, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    397
    gerry
    Mar 7, 2007
  4. Ken Cecka

    arrrrg!

    Ken Cecka, Feb 14, 2009, in forum: VHDL
    Replies:
    14
    Views:
    1,319
    Al Muliman
    Feb 16, 2009
  5. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    228
    Steven Cheng[MSFT]
    Mar 23, 2006
Loading...

Share This Page