Solved

How to update data using class

Posted on 2006-06-26
3
229 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
  • 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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