Solved

How to update data using class

Posted on 2006-06-26
3
224 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now