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
"Manish" <Manish [at] discussions.microsoft.com> wrote in message
news:0B320F85-8E57-4BB9-8866-8108A374C311 [at] microsoft.com...
> Hi Ed,
>
> Please refer to the link below for creating an objectdatasource and
> creating
> the update, delete function.
>
> http://msdn2.microsoft.com/en-gb/library/ms227562.aspx
>
> Regards,
> Manish
> www.ComponentOne.com
>
>
> "Ed Dror" wrote:
>
>> 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( [at] Vendor_Name,
>> [at] Address1, [at] Address2, [at] City, [at] State, [at] zip, [at] Phone, [at] Fax, [at] Email,
>> [at] UserNAme,
>> [at] URL) " & _
>> "SELECT [at] EmployeeID =
>> SCOPE_IDENTITY()", con)
>>
>> cmd.Parameters.Add(" [at] Vendor_Name", SqlDbType.VarChar, 50).Value =
>> Vendor_Name
>> cmd.Parameters.Add(" [at] Address1", SqlDbType.VarChar, 50).Value =
>> Address1
>> cmd.Parameters.Add(" [at] Address2", SqlDbType.VarChar, 50).Value =
>> Address2
>> cmd.Parameters.Add(" [at] City", SqlDbType.VarChar, 50).Value = City
>> cmd.Parameters.Add(" [at] State", SqlDbType.VarChar, 50).Value = State
>> cmd.Parameters.Add(" [at] Zip", SqlDbType.VarChar, 50).Value = Zip
>> cmd.Parameters.Add(" [at] Phone", SqlDbType.VarChar, 50).Value = Phone
>> cmd.Parameters.Add(" [at] Fax", SqlDbType.VarChar, 50).Value = Fax
>> cmd.Parameters.Add(" [at] Email", SqlDbType.VarChar, 50).Value = Email
>> cmd.Parameters.Add(" [at] UserName", SqlDbType.VarChar, 50).Value =
>> UserName
>> cmd.Parameters.Add(" [at] URL", SqlDbType.VarChar, 50).Value = URL
>> Dim p As SqlParameter = cmd.Parameters.Add(" [at] 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= [at] Vendor_Name,Address1= [at] Address1,
>> Address2= [at] Address2, City= [at] City, State= [at] State, Zip= [at] Zip, Phone= [at] Phone,
>> Fax= [at] Fax, Email= [at] Email, UserName= [at] UserName, URL= [at] URL " & _
>> "WHERE Vendor_ID= [at] Vendor_ID"
>> Dim cmd As New SqlCommand(updateString, con)
>> cmd.Parameters.AddWithValue(" [at] Vendor_Name", Vendor_Name)
>> cmd.Parameters.AddWithValue(" [at] Address1", Address1)
>> cmd.Parameters.AddWithValue(" [at] Address2", Address1)
>> cmd.Parameters.AddWithValue(" [at] City", City)
>> cmd.Parameters.AddWithValue(" [at] State", State)
>> cmd.Parameters.AddWithValue(" [at] Zip", Zip)
>> cmd.Parameters.AddWithValue(" [at] Phone", Phone)
>> cmd.Parameters.AddWithValue(" [at] Fax", Fax)
>> cmd.Parameters.AddWithValue(" [at] Email", Email)
>> cmd.Parameters.AddWithValue(" [at] UserName", UserName)
>> cmd.Parameters.AddWithValue(" [at] URL", URL)
>> cmd.Parameters.AddWithValue(" [at] 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= [at] Vendor_ID"
>> Dim cmd As New SqlCommand(deleteString, con)
>> cmd.Parameters.AddWithValue(" [at] 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
>>
>>
>>
>>
