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
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