Re: Error Message could not find a non-generic method

Re: Error Message could not find a non-generic method

am 30.03.2008 16:05:49 von 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

_
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" %>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



Vendor




DeleteMethod="DeleteVendor"
InsertMethod="InsertVendor" SelectMethod="GetVendor"
TypeName="VendorDB" UpdateMethod="UpdateProduct">




































DataSourceID="ObjectDataSource1"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#333333"
GridLines="None">
ForeColor="White" />


ShowSelectButton="True" ButtonType="Button" ShowDeleteButton="True" />

HorizontalAlign="Center" />
ForeColor="#333333" />
ForeColor="White" />







DataSourceID="ObjectDataSource1"
DefaultMode="Insert" ForeColor="#333333" GridLines="None"
Height="50px" Width="125px" Font-Names="Verdana" Font-Size="8pt">
ForeColor="White" />



HorizontalAlign="Center" />

ShowInsertButton="True" />

ForeColor="White" />







Thnaks

Ed Dror


"Jialiang Ge [MSFT]" wrote in message
news:j71QnJ$jIHA.4200@TK2MSFTNGHUB02.phx.gbl...
> 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/ObjectD ataSource-could-
> not-find-a-non_2D00_generic-method-Update-Error.aspx
> https://connect.microsoft.com/VisualStudio/feedback/ViewFeed back.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:
>
>
> ¡­.. (other parameters)
>

>
> 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 (jialge@online.microsoft.com, 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:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.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.
>

Re: Error Message could not find a non-generic method

am 01.04.2008 06:22:14 von 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



"Jialiang Ge [MSFT]" wrote in message
news:yHN7fmwkIHA.360@TK2MSFTNGHUB02.phx.gbl...
> Hello Ed,
>
> I have tested your code carefully, and find a problem in UpdateProduct
> function. The code line
>
> cmd.Parameters.AddWithValue("@Crtd", CrtdUser)
>
> should be
>
> cmd.Parameters.AddWithValue("@CrtdUser", CrtdUser)
>
> otherwise, it will throw an exception "Must declare the variable
> '@CrtdUser'" when we click on Update button.
>
> However, fixing this does not explain why you get the exception "could not
> find a non-generic method". Based on my best, your code runs very well on
> my side. I attach my test project 41722685.zip to this message. You can
> download it with Windows Mail or Outlook Express. In my test project, I
> removed DeleteVendor, InsertVender and the DetailView so that we can focus
> on the UpdateProduct procedure. To create the Vendor table, I use the SQL
> script:
>
> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
> CREATE TABLE [dbo].[Vendor](
> [Vendor_ID] [int] IDENTITY(1,1) NOT NULL,
> [Vendor_Name] [nvarchar](50) NULL,
> [Address1] [nvarchar](50) NULL,
> [Address2] [nvarchar](50) NULL,
> [City] [nvarchar](50) NULL,
> [State] [nvarchar](50) NULL,
> [Zip] [nchar](50) NULL,
> [Phone] [nvarchar](50) NULL,
> [Fax] [nchar](50) NULL,
> [Email] [nchar](50) NULL,
> [CrtdUser] [nchar](50) NULL,
> [URL] [nvarchar](50) NULL,
> CONSTRAINT [PK_tblVendor2] PRIMARY KEY CLUSTERED
> (
> [Vendor_ID] ASC
> )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
> OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
> ) ON [PRIMARY]
>
> I suggest you try my test project, and see if it works on your side, then
> compare it with your solution, to narrow down focuses.
>
> Regards,
> Jialiang Ge (jialge@online.microsoft.com, 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:
> msdnmg@microsoft.com.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> =================================================

Re: Error Message could not find a non-generic method

am 01.04.2008 07:20:22 von jialge

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


¡­.. (other parameters)


Then it will work.

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

Regards,
Jialiang Ge (jialge@online.microsoft.com, 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:
msdnmg@microsoft.com.

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