?
Solved

store procedure

Posted on 2004-11-12
7
Medium Priority
?
196 Views
Last Modified: 2008-03-04
Hi, its friday evening  and i have got to do this!!!

I have a datagrid and the usual update, delete etc buttons. Now how can i update a get the update function to work. basically I need to call a store procedure which is in my "Access.vb class"

this is the Stored procedure in the Access.vb
====================================
Public Sub UpdateSection(ByVal SectionName As String)
            Dim DL As New DataLayer
            Dim sqlparams As New ArrayList
            sqlparams.Add(Dl.AddParameter("@SectionName", "SqlDbType.NVarChar", 50, SectionName, ParameterDirection.Input))
            Try
                DL.ExecuteStoredProc("spUpdateSection", sqlparams)
            Catch ex As Exception
                Throw New ArgumentException(ex.Message.ToString())
            End Try
        End Sub
===============================================
and in my grid codebehind this is where i am trying to call the store procedure
===========================================================
Public Sub OnUpdate(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
        'initialize to update the datagrid ctrl

        Dim item As String = CType(e.Item.FindControls("txtsectionname"), TextBox).Text()
        Dim updater As New Sections
      =====================================================
txtsectionname is from this----

<EditItemTemplate>
                                                      <asp:TextBox Runat="server" ID="txtSectionName" Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"SectionName"))%>' Width="150"/>
                                                </EditItemTemplate>

pls help,
thanks
0
Comment
Question by:SirReadAlot
  • 4
  • 2
7 Comments
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 12567671
Hmmm. not familiar with using the DataLayer type.

I do not see in your datagrid codebehind any code referencing the sub UpdateSection.

Sorry, not much help i know.

KS
0
 

Author Comment

by:SirReadAlot
ID: 12567800
cool!!
0
 
LVL 16

Expert Comment

by:MikeMCSD
ID: 12568620
add this button:

<asp:Button ID="lnkAdd" Runat=server Text="Update"  CommandName="UpdateAccess" ></asp:Button>

then add this event:

Private Sub grid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grid.ItemCommand

        If e.CommandName = "UpdateAccess" Then

        UpdateSection.UpdateSection(SectionName)
.. ..

if you have other commands, list them here and check the e.CommandName value
for the one clicked.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SirReadAlot
ID: 12577940
thanks mike
i shall try on monday!!
0
 
LVL 16

Accepted Solution

by:
MikeMCSD earned 2000 total points
ID: 12579355
Sir, forget that last post . . I think you want something more like this:

Public Sub OnUpdate(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
        'initialize to update the datagrid ctrl

        Dim item As String = CType(e.Item.FindControls("txtsectionname"), TextBox).Text()

        Access.UpdateSection(item)

       'then bind the data to the grid again here . . .

       
0
 

Author Comment

by:SirReadAlot
ID: 12582180
okay, am trying it now
0
 

Author Comment

by:SirReadAlot
ID: 12582399
thanks for the tip,

for those interested, this is what i did

Public Sub OnUpdate(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
        'initialize to update the datagrid ctrl
        Dim item As String = CType(e.Item.FindControl("txtSectionName"), TextBox).Text()
        Dim Update As New Sections
        Update.UpdateSection(dgSection.DataKeys(e.Item.ItemIndex), item)
        dgSection.EditItemIndex = -1
        BindGrid()
    End Sub
---------------------------------------this is the stored procedure
Public Function UpdateSection(ByVal SectionID As Integer, ByVal SectionName As String)
            Dim DL As New DataLayer
            Dim sqlparams As New ArrayList
            sqlparams.Add(DL.AddParameter("@SectionID", "SqlDbType.Int", 4, SectionID, ParameterDirection.Input))
            sqlparams.Add(DL.AddParameter("@SectionName", "SqlDbType.NVarChar", 50, SectionName, ParameterDirection.Input))
            Try
                DL.ExecuteStoredProc("spUpdateSection", sqlparams)
            Catch ex As Exception
                Throw New ArgumentException(ex.Message.ToString())
            End Try
        End Function

thanks
SirReadAlot
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question