Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Arrrrg !!!! ObjectDataSource Issues

Reply
Thread Tools

Arrrrg !!!! ObjectDataSource Issues

 
 
WertmanTheMad
Guest
Posts: n/a
 
      10-08-2004
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").Co nnectionString

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

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").Co nnectionString

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

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>
<asparameter Type="String"
Name="au_id"></asparameter>
</DeleteParameters>
<UpdateParameters>
<asparameter Type="String"
Name="au_id"></asparameter>
<asparameter Type="String"
Name="au_lname"></asparameter>
<asparameter Type="String"
Name="au_fname"></asparameter>
<asparameter Type="String"
Name="state"></asparameter>
</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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF0cmljay5PLklnZQ==?=
Guest
Posts: n/a
 
      10-08-2004
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").Co nnectionString
>
> Dim dbConnection As System.Data.IDbConnection = New
> System.Data.SqlClient.SqlConnection(connectionStri ng)
>
> 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").Co nnectionString
>
> Dim dbConnection As System.Data.IDbConnection = New
> System.Data.SqlClient.SqlConnection(connectionStri ng)
>
> 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>
> <asparameter Type="String"
> Name="au_id"></asparameter>
> </DeleteParameters>
> <UpdateParameters>
> <asparameter Type="String"
> Name="au_id"></asparameter>
> <asparameter Type="String"
> Name="au_lname"></asparameter>
> <asparameter Type="String"
> Name="au_fname"></asparameter>
> <asparameter Type="String"
> Name="state"></asparameter>
> </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
>

 
Reply With Quote
 
 
 
 
WertmanTheMad
Guest
Posts: n/a
 
      10-08-2004
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").Co nnectionString
> >
> > Dim dbConnection As System.Data.IDbConnection = New
> > System.Data.SqlClient.SqlConnection(connectionStri ng)
> >
> > 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").Co nnectionString
> >
> > Dim dbConnection As System.Data.IDbConnection = New
> > System.Data.SqlClient.SqlConnection(connectionStri ng)
> >
> > 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>
> > <asparameter Type="String"
> > Name="au_id"></asparameter>
> > </DeleteParameters>
> > <UpdateParameters>
> > <asparameter Type="String"
> > Name="au_id"></asparameter>
> > <asparameter Type="String"
> > Name="au_lname"></asparameter>
> > <asparameter Type="String"
> > Name="au_fname"></asparameter>
> > <asparameter Type="String"
> > Name="state"></asparameter>
> > </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
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
arrrrg! Ken Cecka VHDL 14 02-16-2009 11:29 AM
Issues with Stongly-Typed ObjectDataSource's UpdateMethod =?Utf-8?B?cm9zczYxMw==?= ASP .Net 1 03-07-2007 01:46 PM
ObjectDataSource method as another ObjectDataSource David Thielen ASP .Net Web Controls 3 03-23-2006 01:50 AM
Re: Windows XP Pro clean install issues, SP2 issues too... pcbutts1 Computer Support 0 07-06-2005 04:52 PM
SNMP Issues in Cisco Routers; Vulnerability Issues in TCP =?iso-8859-1?Q?Frisbee=AE?= MCSE 0 04-21-2004 03:00 PM



Advertisments