Question : Incorrect Syntax when running stored procedure

This seems like a SQL topic but if not, let me know and I will re-post in the appropriate area.

I am running a stored procedure that is taking in parameters from an ASP.NET page.  Below is code from the ASPX page:

    Protected Function GetSelectedEmployees_termList(ByVal EMP_ID As String, ByVal inactivedate As DateTime) As DataSet
        Dim ds As New DataSet
        Dim sqlconn As New SqlConnection(AppSettings("ocusoftcentralconnectionstring"))
        Dim sqlcomm As New SqlCommand("INTRANET_TERMINATE_EMPLOYEE", sqlconn)
        sqlcomm.Parameters.Add("@EMP_ID", SqlDbType.VarChar).Value = lstBxEmployeeList.SelectedValue
        sqlcomm.Parameters.Add("@INACTIVEDATE", SqlDbType.DateTime).Value = txtBxEffectiveDate.Text

        sqlconn.Open()
        Dim sqldataadapter As New SqlDataAdapter(sqlcomm)
        sqldataadapter.Fill(ds) <-------errors out here.

        Return ds
    End Function
------------------------------------------------------------------------------------
    Protected Sub btnTermEmpConfirm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTermEmpConfirm.Click
        Dim inactivedate As DateTime
        Dim emp_id As Integer

        GetSelectedEmployees_termList(emp_id, inactivedate)

    End Sub
--------------------------------------------------------------------------------------

Below is the stored procedure INTRANET_TERMINATE_EMPLOYEE:

CREATE PROCEDURE dbo.INTRANET_TERMINATE_EMPLOYEE
(
@INACTIVEDATE as datetime,
@emp_ID as varchar)
AS
update employees
set [active/inactive] = 'I', inactivedate = convert(datetime,@inactivedate,103)
where emp_id = @EMP_ID
GO
-----------------------------------------------------------------------------------------------

Below is the details from the error message I receive:

Line 1: Incorrect syntax near 'INTRANET_TERMINATE_EMPLOYEE'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'INTRANET_TERMINATE_EMPLOYEE'.

Source Error:


Line 84:         sqlconn.Open()
Line 85:         Dim sqldataadapter As New SqlDataAdapter(sqlcomm)
Line 86:         sqldataadapter.Fill(ds)
Line 87:
Line 88:         Return ds
 

Source File: E:\OCCENTRAL\Operations\TermEmployee.aspx.vb    Line: 86

Stack Trace:


[SqlException (0x80131904): Line 1: Incorrect syntax near 'INTRANET_TERMINATE_EMPLOYEE'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +52
   System.Data.SqlClient.SqlDataReader.get_MetaData() +130
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +371
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +45
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +162
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +35
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +32
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +183
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +308
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +151
   Operations_TermEmployee.GetSelectedEmployees_termList(String EMP_ID, DateTime inactivedate) in E:\OCCENTRAL\Operations\TermEmployee.aspx.vb:86
   Operations_TermEmployee.btnTermEmpConfirm_Click(Object sender, EventArgs e) in E:\OCCENTRAL\Operations\TermEmployee.aspx.vb:95
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +116
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

If this needs to be posted in another area, let me know.  Just seems like it is a SQL SYNTAX issue....thought I'd try here first...

Thanks for the assist!

Sean

Answer : Incorrect Syntax when running stored procedure

I see. then scratch the DataAdapter. DataAdapter is to RETRIEVE values from a Query (SELECT) to the datatable object.
you are running a procedure to update data, so simply run this:

sqlconn.Open()
sqlcomm.ExecuteNonQuery()

Random Solutions  
 
programming4us programming4us