Error Message could not find a non-generic method

E

Ed Dror

Hi there,

I'm using ASP.NET 2.0 with Visual studio 2005 Pro and SQL Server 2005 Dev.

Based on Microsoft toturial on ObjectDataSource I ctreated a class look like
this

*** VendorDB.vb ***

Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic

<DataObject(True)> _
Public Class VendorDB

Const conString As String = "Data Source=(local);Initial
Catalog=Catalog;User ID=xxxx;Password=xxxxxx"

Public Shared Function GetVendor() As SqlDataReader
Dim con As New SqlConnection(conString)
Dim selectString As String = "SELECT * From Vendor"
Dim cmd As New SqlCommand(selectString, con)
con.Open()
Dim dtr As SqlDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return dtr
End Function

Public Function InsertVendor(ByVal Vendor_ID As String, _
ByVal Vendor_Name As String, _
ByVal Address1 As String, _
ByVal Address2 As String, _
ByVal City As String, _
ByVal State As String, _
ByVal Zip As String, _
ByVal Phone As String, _
ByVal Fax As String, _
ByVal Email As String, _
ByVal UserName As String, _
ByVal URL As String) As Integer

Dim con As New SqlConnection(conString)
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO Vendor " & _
" (Vendor_Name, Address1,
Address2, City, State, Zip, Phone, Fax, Email, UserName, URL) " & _
" Values(@Vendor_Name,
@Address1, @Address2, @City, @State, @zip, @Phone, @Fax, @Email, @UserNAme,
@URL) " & _
"SELECT @EmployeeID =
SCOPE_IDENTITY()", con)

cmd.Parameters.Add("@Vendor_Name", SqlDbType.VarChar, 50).Value =
Vendor_Name
cmd.Parameters.Add("@Address1", SqlDbType.VarChar, 50).Value =
Address1
cmd.Parameters.Add("@Address2", SqlDbType.VarChar, 50).Value =
Address2
cmd.Parameters.Add("@City", SqlDbType.VarChar, 50).Value = City
cmd.Parameters.Add("@State", SqlDbType.VarChar, 50).Value = State
cmd.Parameters.Add("@Zip", SqlDbType.VarChar, 50).Value = Zip
cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 50).Value = Phone
cmd.Parameters.Add("@Fax", SqlDbType.VarChar, 50).Value = Fax
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value = Email
cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value =
UserName
cmd.Parameters.Add("@URL", SqlDbType.VarChar, 50).Value = URL
Dim p As SqlParameter = cmd.Parameters.Add("@Vendor_ID",
SqlDbType.Int)
p.Direction = ParameterDirection.Output

Dim newEmployeeID As Integer = 0

Try
con.Open()

cmd.ExecuteNonQuery()

newEmployeeID = CInt(p.Value)
Catch e As SqlException
e.ErrorCode.ToString()
Finally
con.Close()
End Try

Return newEmployeeID
End Function

Public Shared Sub UpdateProduct(ByVal original_Vendor_ID _
As Integer, _
ByVal Vendor_Name As String, _
ByVal Address1 As String, _
ByVal Address2 As String, _
ByVal City As String, _
ByVal State As String, _
ByVal Zip As String, _
ByVal Phone As String, _
ByVal Fax As String, _
ByVal Email As String, _
ByVal UserName As String, _
ByVal URL As String)
Dim con As New SqlConnection(conString)
Dim updateString As String = "UPDATE Vendor " & _
"SET Vendor_Name=@Vendor_Name,Address1=@Address1,
Address2=@Address2, City=@City, State=@State, Zip=@Zip, Phone=@Phone,
Fax=@Fax, Email=@Email, UserName=@UserName, URL=@URL " & _
"WHERE Vendor_ID=@Vendor_ID"
Dim cmd As New SqlCommand(updateString, con)
cmd.Parameters.AddWithValue("@Vendor_Name", Vendor_Name)
cmd.Parameters.AddWithValue("@Address1", Address1)
cmd.Parameters.AddWithValue("@Address2", Address1)
cmd.Parameters.AddWithValue("@City", City)
cmd.Parameters.AddWithValue("@State", State)
cmd.Parameters.AddWithValue("@Zip", Zip)
cmd.Parameters.AddWithValue("@Phone", Phone)
cmd.Parameters.AddWithValue("@Fax", Fax)
cmd.Parameters.AddWithValue("@Email", Email)
cmd.Parameters.AddWithValue("@UserName", UserName)
cmd.Parameters.AddWithValue("@URL", URL)
cmd.Parameters.AddWithValue("@Vendor_ID", original_Vendor_ID)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
Finally
con.Close()
End Try


End Sub

Public Shared Sub DeleteVendor(ByVal original_Vendor_ID As Integer)
Dim con As New SqlConnection(conString)
Dim deleteString As String = "DELETE Vendor " & _
"WHERE Vendor_ID=@Vendor_ID"
Dim cmd As New SqlCommand(deleteString, con)
cmd.Parameters.AddWithValue("@Vendor_ID", original_Vendor_ID)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
Finally
con.Close()
End Try
End Sub

End Class

Now I created GridView with Edit only method
And I changed the OldValueParameterString to {0}

When I'm click on Edit and Update I'm getting an Error

ObjectDataSource 'ObjectDataSource1'
could not find a non-generic method 'UpdateProduct'
that has parameters: original_Vendor_ID, Vendor_Name,
Address1, Address2, City, State, Zip,
Phone, Fax, Email, UserName, URL, Vendor_ID, CrtdUser.

What I did wrong? and how to fix this

Thanks,
Ed Dror
 
J

Jialiang Ge [MSFT]

Hello Ed,

The ASP.NET error "could not find a non-generic method" caused by naming
rules between OldValuesParameterFormatString and update function Parameter
name is a very common problem. There can be various workarounds for
different scenarios. For example:

http://aspadvice.com/blogs/ssmith/archive/2007/02/17/ObjectDataSource-could-
not-find-a-non_2D00_generic-method-Update-Error.aspx
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedba
ckID=260674
http://weblogs.asp.net/bradygaster/archive/2006/09/26/How-to-Bloody-Your-For
ehead.aspx
http://geekswithblogs.net/mnf/archive/2006/08/30/89734.aspx
http://forums.asp.net/t/969187.aspx
http://msdn2.microsoft.com/en-us/library/bb332382.aspx

But based on my observation of your sample code, a possible quick
resolution is:

Step1. Change the first parameter name of UpdateProduct from
original_Vendor_ID to Vendor_ID (I assume Vendor_ID is in your GridView's
DataKeyNames property), and update the code inside UpdateProduct
accordingly.

Step2. Change the parameter name defined in your ObjectDataSource from
original_Vendor_ID to Vendor_ID:
<UpdateParameters>
<asp:parameter Name=" Vendor_ID" Type="Int32" />
¡­.. (other parameters)
</UpdateParameters>

Step3. Compile the project and try the update again.

If this resolution does not help, please paste your aspx code of the
GridView here, I need to see how you defined the DataKeyNames property. You
may also try other workarounds mentioned in the above links for you
specific scenario.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
O

Oded Dror

Jialiang,

I remove the "Original" word from my code and changed Vendor_ID As Integer
to Int32
Still same issue, Here are the code (vb and aspx)

***VendorDB.vb***

Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic

<DataObject(True)> _
Public Class VendorDB

Const conString As String = "Data Source=(local);Initial
Catalog=Catalog;User ID=xxxxxx;Password=xxxxxx"

Public Shared Function GetVendor() As SqlDataReader
Dim con As New SqlConnection(conString)
Dim selectString As String = "SELECT * From Vendor"
Dim cmd As New SqlCommand(selectString, con)
con.Open()
Dim dtr As SqlDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return dtr
End Function

Public Function InsertVendor(ByVal Vendor_ID As Int32, _
ByVal Vendor_Name As String, _
ByVal Address1 As String, _
ByVal Address2 As String, _
ByVal City As String, _
ByVal State As String, _
ByVal Zip As String, _
ByVal Phone As String, _
ByVal Fax As String, _
ByVal Email As String, _
ByVal CrtdUser As String, _
ByVal URL As String) As Integer

Dim con As New SqlConnection(conString)
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO Vendor
(Vendor_Name, Address1, Address2, City, State, Zip, Phone, Fax, Email,
CrtdUser, URL) " & _
" Values(@Vendor_Name, @Address1, @Address2, @City, @State, @zip,
@Phone, @Fax, @Email, @CrtdUser, @URL))")
cmd.Parameters.Add("@Vendor_Name", SqlDbType.VarChar, 50).Value =
Vendor_Name
cmd.Parameters.Add("@Address1", SqlDbType.VarChar, 50).Value =
Address1
cmd.Parameters.Add("@Address2", SqlDbType.VarChar, 50).Value =
Address2
cmd.Parameters.Add("@City", SqlDbType.VarChar, 50).Value = City
cmd.Parameters.Add("@State", SqlDbType.VarChar, 50).Value = State
cmd.Parameters.Add("@Zip", SqlDbType.VarChar, 50).Value = Zip
cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 50).Value = Phone
cmd.Parameters.Add("@Fax", SqlDbType.VarChar, 50).Value = Fax
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value = Email
cmd.Parameters.Add("@CrtdUser", SqlDbType.VarChar, 50).Value =
CrtdUser
cmd.Parameters.Add("@URL", SqlDbType.VarChar, 50).Value = URL

Dim p As SqlParameter = cmd.Parameters.Add("@Vendor_ID",
SqlDbType.Int)
p.Direction = ParameterDirection.Output

Dim newEmployeeID As Integer = 0

Try
con.Open()

cmd.ExecuteNonQuery()

newEmployeeID = CInt(p.Value)
Catch e As SqlException
e.ErrorCode.ToString()
Finally
con.Close()
End Try

Return newEmployeeID
End Function

Public Shared Sub UpdateProduct(ByVal Vendor_ID As Int32, _
ByVal Vendor_Name As String, _
ByVal Address1 As String, _
ByVal Address2 As String, _
ByVal City As String, _
ByVal State As String, _
ByVal Zip As String, _
ByVal Phone As String, _
ByVal Fax As String, _
ByVal Email As String, _
ByVal CrtdUser As String, _
ByVal URL As String)
Dim con As New SqlConnection(conString)
Dim updateString As String = "UPDATE Vendor SET
Vendor_Name=@Vendor_Name,Address1=@Address1, Address2=@Address2, City=@City,
State=@State, Zip=@Zip, Phone=@Phone, Fax=@Fax, Email=@Email,
CrtdUser=@CrtdUser, URL=@URL WHERE Vendor_ID=@Vendor_ID"
Dim cmd As New SqlCommand(updateString, con)
cmd.Parameters.AddWithValue("@Vendor_Name", Vendor_Name)
cmd.Parameters.AddWithValue("@Address1", Address1)
cmd.Parameters.AddWithValue("@Address2", Address1)
cmd.Parameters.AddWithValue("@City", City)
cmd.Parameters.AddWithValue("@State", State)
cmd.Parameters.AddWithValue("@Zip", Zip)
cmd.Parameters.AddWithValue("@Phone", Phone)
cmd.Parameters.AddWithValue("@Fax", Fax)
cmd.Parameters.AddWithValue("@Email", Email)
cmd.Parameters.AddWithValue("@Crtd", CrtdUser)
cmd.Parameters.AddWithValue("@URL", URL)
cmd.Parameters.AddWithValue("@Vendor_ID", Vendor_ID)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
Finally
con.Close()
End Try


End Sub

Public Shared Sub DeleteVendor(ByVal Vendor_ID As Integer)
Dim con As New SqlConnection(conString)
Dim deleteString As String = "DELETE Vendor " & _
"WHERE Vendor_ID=@Vendor_ID"
Dim cmd As New SqlCommand(deleteString, con)
cmd.Parameters.AddWithValue("@Vendor_ID", Vendor_ID)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
Finally
con.Close()
End Try
End Sub

End Class


*****Here is the aspx page******

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb"
Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Vendor</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="DeleteVendor"
InsertMethod="InsertVendor" SelectMethod="GetVendor"
TypeName="VendorDB" UpdateMethod="UpdateProduct">
<DeleteParameters>
<asp:parameter Name="Vendor_ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Vendor_ID" Type="Int32" />
<asp:parameter Name="Vendor_Name" Type="String" />
<asp:parameter Name="Address1" Type="String" />
<asp:parameter Name="Address2" Type="String" />
<asp:parameter Name="City" Type="String" />
<asp:parameter Name="State" Type="String" />
<asp:parameter Name="Zip" Type="String" />
<asp:parameter Name="Phone" Type="String" />
<asp:parameter Name="Fax" Type="String" />
<asp:parameter Name="Email" Type="String" />
<asp:parameter Name="CrtdUser" Type="String" />
<asp:parameter Name="URL" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Vendor_ID" Type="String" />
<asp:parameter Name="Vendor_Name" Type="String" />
<asp:parameter Name="Address1" Type="String" />
<asp:parameter Name="Address2" Type="String" />
<asp:parameter Name="City" Type="String" />
<asp:parameter Name="State" Type="String" />
<asp:parameter Name="Zip" Type="String" />
<asp:parameter Name="Phone" Type="String" />
<asp:parameter Name="Fax" Type="String" />
<asp:parameter Name="Email" Type="String" />
<asp:parameter Name="CrtdUser" Type="String" />
<asp:parameter Name="URL" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>

</div>
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4"
DataSourceID="ObjectDataSource1"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#333333"
GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowEditButton="True"
ShowSelectButton="True" ButtonType="Button" ShowDeleteButton="True" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<br />
<br />
<asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4"
DataSourceID="ObjectDataSource1"
DefaultMode="Insert" ForeColor="#333333" GridLines="None"
Height="50px" Width="125px" Font-Names="Verdana" Font-Size="8pt">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<Fields>
<asp:CommandField ButtonType="Button"
ShowInsertButton="True" />
</Fields>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:DetailsView>
</form>
</body>
</html>

Thnaks

Ed Dror
 
O

Oded Dror

Manish,

I copied the code but I'm getting a label says No Record...

Could you show me some code that has records? or anything that work.

Thanks,
Ed Dror
 
O

Oded Dror

Jialiang,

It works,

Thank you very much for your help.

Do you think that the rest of the code wil work (Insert and Delete methods)?

Oded Dror
 
J

Jialiang Ge [MSFT]

Hello Oded,

We need to update the rest of the code in the same way as that of
UpdateProduct:

Step1. Change the first parameter name of UpdateProduct from
original_Vendor_ID to Vendor_ID (I assume Vendor_ID is in your GridView's
DataKeyNames property), and update the code inside UpdateProduct
accordingly.

Step2. Change the parameter name defined in your ObjectDataSource from
original_Vendor_ID to Vendor_ID
<UpdateParameters>
<asp:parameter Name=" Vendor_ID" Type="Int32" />
¡­.. (other parameters)
</UpdateParameters>

Then it will work.

If you encounter any other problems, feel free to let me know.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top