Solved

How to update data using class

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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