DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: VBNet2008 Create Store Procedure to create new record

  1. #1
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319

    VBNet2008 Create Store Procedure to create new record

    Hi Good and Awesome guys,

    Window application.

    I need your help and suggestions. I am trying to write Sql Server Store Procedure to create a new record in NorthWind Table ORDERS. I seem to received error message under the INSERT statement.

    Here are my coding scripts
    Code:
    Private Sub btnUpdate_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnUpdate.Click
    
      'create Order record using store procedure
       Try
          Dim connStr As String 
               connstr &= "Integrated Security = SSPI; Data Source = LocalHost; “
               connstr &= “Persist Security Info = False; “
               connstr &= “ Initial Catalog = NorthWind"
    	
          Dim sqlConn As New SqlConnection(connStr)
          Dim sqlCmd As New SqlCommand
    
          sqlCmd.Connection = sqlConn
          sqlCmd.CommandText = "SPCreateNewOrder"
          sqlCmd.CommandType = CommandType.StoredProcedure
    
          'create parameters
           With sqlCmd
              .Parameters.Add("@CustomerId",SqlDbType.NChar,5).Value = txtCustomerId.text)
              .Parameters.Add("@EmployeeId", SqlDbType.Int,4).Value =  cboStaff.SelectedItem(0) )
              .Parameters.Add("@OrderDate", SqlDbType.DateTime, 8.value = txtDteOrder.Text)
           End With
    
           sqlConn.Open()
           sqlCmd.ExecuteNonQuery()
           sqlConn.Close()
    
       Catch ex As Exception
             MessageBox.Show(ex.Message)
       End Try
    End Sub
    
    ---------------------------------------------
    SQL SERVER STORE PROCEDURE
    
    CREATE PROCEDURE SPCreateNewOrder
    	@Customerid  nchar(4),  @EmployeeId int(4),@OrderDate datetime(8)
    As
    	Insert into Orders
    	   (CustomerId,EmployeeId,OrderDate)
    	values
    	   (@Customerid  nchar(4), @EmployeeId int(4),	@OrderDate datetime(8) )	 
    
    GO

    Please help me as I have not written Store Procedure before.
    Thank you very much.
    Last edited by Lennie; 02-28-2010 at 12:58 AM. Reason: type error
    Cheers,
    Lennie

Similar Threads

  1. Replies: 0
    Last Post: 02-17-2002, 10:39 AM
  2. GOSUB vs. Macros vs. Nested Functions
    By Jonathan Allen in forum .NET
    Replies: 331
    Last Post: 03-19-2001, 09:00 AM
  3. temporal table in store procedure
    By Alejandro E. in forum Database
    Replies: 1
    Last Post: 11-17-2000, 10:00 AM
  4. Replies: 0
    Last Post: 11-10-2000, 02:58 PM
  5. Stored Procedure Insert / Update Help
    By Jeremy Samkowiak in forum ASP.NET
    Replies: 0
    Last Post: 09-16-2000, 12:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center