Re: Error Message could not find a non-generic method
am 30.03.2008 16:05:49 von Oded DrorJialiang,
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">
Thnaks
Ed Dror
"Jialiang Ge [MSFT]"
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.
>