This is a migrated thread and some comments may be shown as answers.

No Update and No Error using ObjectDataSource

4 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 03 Jan 2009, 08:37 AM

Hi

I have been trying to figure out what went wrong. I followed the example on th code library Automatic insert/update/delete using ObjectDataSource.

please help. Thanks a million.

ALTER PROCEDURE [dbo].[spUpdPerInfo]
@ID as nvarchar(100),
@ContactNo as nvarchar(20),
@Email as nvarchar(100),
@ModDate as datetime,

as

UPDATE [tblPerInfo] SET [ContactNo] = @ContactNo, [Email] = @Email, [ModDate] = @ModDate WHERE [ID] = @ID

--------------------------------------------------------------------------------------------------------------------------------------------------

Public Sub PerInfo_Update(ByVal ID As String, ByVal ContactNo As String, ByVal Email As String)

        Dim sqlcmd As New SqlCommand("spUpdPerInfo", getConn)
        sqlcmd.CommandType = CommandType.StoredProcedure
 
        sqlcmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.NVarChar, 50))
        sqlcmd.Parameters("@ID").Value = ID
        sqlcmd.Parameters.Add(New SqlParameter("@ContactNo", SqlDbType.NVarChar, 50))
        sqlcmd.Parameters("@ContactNo").Value = ContactNo

        sqlcmd.Parameters.Add(New SqlParameter("@Email", SqlDbType.NVarChar, 500))
        sqlcmd.Parameters("@Email").Value = Email

        sqlcmd.Parameters.Add(New SqlParameter("@ModDate", SqlDbType.DateTime))
        sqlcmd.Parameters("@ModDate").Value = DateTime.Now

        sqlcmd.ExecuteNonQuery()

        getConn.Close()

End Sub

-------------------------------------------------------------------------------------------------------------
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True"
                    DataSourceID="ObjectDataSource1" GridLines="None" 
                    AutoGenerateColumns="False" AllowAutomaticUpdates="True">
<MasterTableView DataKeyNames="ID" DataSourceID="ObjectDataSource1">
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn Visible="False" Resizable="False">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>

    <Columns>
        <telerik:GridBoundColumn DataField="ID" DataType="System.String" HeaderText="ID"
          readonly="true"  UniqueName="ID" SortExpression="ID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ContactNo" HeaderText="Contact No"
            UniqueName="ContactNo"  SortExpression="ContactNo">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Email" HeaderText="Email"
            UniqueName="Email"  SortExpression="Email">
        </telerik:GridBoundColumn >
     </Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
<EditFormSettings>

<PopUpSettings ScrollBars="None"></PopUpSettings>
</EditFormSettings>
</MasterTableView>
                </telerik:RadGrid>
                <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                    SelectMethod="SearchID" TypeName="DAL" UpdateMethod="PerInfo_Update">
                    <UpdateParameters>
                        <asp:Parameter Name="ID" Type="String" />
                        <asp:Parameter Name="ContactNo" Type="String" />
                        <asp:Parameter Name="Email" Type="String" />                    
                    </UpdateParameters>
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="alpha" Name="choice" SessionField="choice"
                            Type="String" />
                        <asp:SessionParameter DefaultValue="A" Name="search" SessionField="value"
                            Type="String" />
                    </SelectParameters>
                </asp:ObjectDataSource>
          

4 Answers, 1 is accepted

Sort by
0
L
Top achievements
Rank 1
answered on 03 Jan 2009, 08:54 AM
hi

There is an error that says "Exception has been thrown by the target of an invocation"

My Code behind:

Imports

System.Data

 

Imports

System.Data.SqlClient

 

Imports

Telerik.Web.UI

 

Partial

Class PerInfo_Default

 

 

Inherits System.Web.UI.Page

 

 

Dim x As New DAL

 

 

Protected Sub RadMenu3_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs)

 

 

Select Case e.Item.Value

 

 

Case "All"

 

Session(

"choice") = "All"

 

Session(

"value") = e.Item.Value

 

 

Case Else

 

Session(

"choice") = "alpha"

 

Session(

"value") = e.Item.Value

 

 

End Select

 

 

End Sub

 

 

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

 

 

Dim ctrl As alphalist = CType(Me.Master.FindControl("alphalist1"), alphalist)

 

 

AddHandler ctrl.RadmemuEvent, AddressOf Me.RadMenu3_ItemClick

 

 

End Sub

 

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

 

If Not IsPostBack Then

 

Session(

"choice") = "alpha"

 

Session(

"value") = "A"

 

 

End If

 

 

End Sub

 

 

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

 

Session(

"choice") = "search"

 

Session(

"value") = txtSearch.Text

 

 

End Sub

 

End

Class

 

0
Vlad
Telerik team
answered on 05 Jan 2009, 08:12 AM
Hello L,

Can you post the stack trace?

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
L
Top achievements
Rank 1
answered on 05 Jan 2009, 05:04 PM
hi

I am so sorry, but i have not use stack trace before. how do i capture it? Thanks
0
L
Top achievements
Rank 1
answered on 06 Jan 2009, 03:56 AM
hi

Are you able to recreate the error that i had based on the code sample i have given? thanks
Tags
Grid
Asked by
L
Top achievements
Rank 1
Answers by
L
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or