Results 1 to 6 of 6

Thread: Using stored proc to insert data to mssql database *Resolved*

Threaded View

  1. #1

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Using stored proc to insert data to mssql database *Resolved*

    Here is the routing I use:
    VB Code:
    1. Public Sub InsertData(ByRef SQL As String, ByRef parameters() As InputParameter)
    2.         '1. Create a connection
    3.         Dim myConnection As New SqlClient.SqlConnection(GetConnection)
    4.  
    5.         '2. Create the command object, passing in the SQL string or stored proc name
    6.         Dim sqcmd As New SqlClient.SqlCommand(SQL, myConnection)
    7.         sqcmd.Connection = myConnection
    8.         sqcmd.CommandType = CommandType.StoredProcedure
    9.  
    10.         '3. Add parameters as needed
    11.         If Not parameters Is Nothing Then
    12.             For Each parm As InputParameter In parameters
    13.                 sqcmd.Parameters.Add(New SqlClient.SqlParameter(parm.Name, parm.Type, parm.Length)).Value = parm.Value
    14.             Next
    15.         End If
    16.  
    17.         'Execute Stored Proc
    18.         myConnection.Open()
    19.         sqcmd.ExecuteNonQuery()
    20.         myConnection.Close()
    21.  
    22.     End Sub
    Here's the exception: Exception Details: System.Data.SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated.

    It seems very straight forward, but I've rechecked everthing serveral times, and none of my values are larger than the stored procedure is expecting. I'm stumped, am I just doing something very wrong here?
    Last edited by wild_bill; Nov 28th, 2005 at 03:14 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
  •  



Click Here to Expand Forum to Full Width