Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to update data using class

Posted on 2006-06-26
3
Medium Priority
?
235 Views
Last Modified: 2010-04-23
Normally, I insert data like this for my web pages (VB.NET):

        cmd = New SqlCommand("Add_NewOrder", Conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim NewCateringOrderID As SqlParameter
        NewCateringOrderID = New SqlParameter("@NewCateringOrderID", SqlDbType.BigInt)
        NewCateringOrderID.Direction = ParameterDirection.Output
        cmd.Parameters.Add(NewCateringOrderID)

        ' pass customer info to stored proc
        cmd.Parameters.Add("@EventDate", txtEventDate.Text)
        cmd.Parameters.Add("@FirstName", txtFName.Text)

        cmd.ExecuteNonQuery()

I am taking a test for a job, and I am guessing they don't want m e to do it this way.  Is there a way to shove an insert into a class as a method then somehow use it to do the insert?  How would I pass parameters or create the right parameters though...meaning if I called the method by creating an instance of the class, how would it know which parameters to create if you wanted to reuse the method?

and what about an update method?
0
Comment
Question by:dba123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16983609
When the Update method is called, changes in the DataSet are copied back to the database and the appropriate
data adpater's InsertCommand, DeleteCommand, or UpdateCommand is executed.
0
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 2000 total points
ID: 16983694
Public Class Test
    Dim EventDate As String
    Dim FirstName As String
    Public Property Event_Date() As String
        Get
            Return EventDate
        End Get
        Set(ByVal Value As String)
            EventDate = Value
        End Set
    End Property

    Public Property First_Name() As String
        Get
            Return FirstName
        End Get
        Set(ByVal Value As String)
            FirstName = Value
        End Set
    End Property

End Class


Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim t As New Test
        t.Event_Date = "12-06-2006"
        t.FirstName = "xyz"

        cmd = New SqlCommand("Add_NewOrder", Conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim NewCateringOrderID As SqlParameter
        NewCateringOrderID = New SqlParameter("@NewCateringOrderID", SqlDbType.BigInt)
        NewCateringOrderID.Direction = ParameterDirection.Output
        cmd.Parameters.Add(NewCateringOrderID)

        ' pass customer info to stored proc
        cmd.Parameters.Add("@EventDate", t.Event_Date)
        cmd.Parameters.Add("@FirstName", t.FirstName)

        cmd.ExecuteNonQuery()

    End Sub

End Class
0
 
LVL 2

Expert Comment

by:Bill_PSC
ID: 16984182
If you use the Data Apdapter's update method you must first endcurrentedit. ie:

 Me.BindingContext(DS, "DT").EndCurrentEdit()
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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