PsychoCoder
Programmer
OK,
I have a stored procedure entering data, I am then selecting the SCOPE_IDENTITY to get the id of the record, in my code behind I have this code which, in theory, will execute the SP and return the ID, problem is Im getting a reference not set to an instance of an object error. The code is as follows:
The bold line is where Im getting the error. By the way at the top of the page I have:
So those variables are declared.
The stored procedure is as follows:
Ive never used ExecuteScalar before so what am I doing wrong?
Senior Qik III,.Net,SQL Programmer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have a stored procedure entering data, I am then selecting the SCOPE_IDENTITY to get the id of the record, in my code behind I have this code which, in theory, will execute the SP and return the ID, problem is Im getting a reference not set to an instance of an object error. The code is as follows:
Code:
Dim NewId As Integer
'##INSERT APP INFO##
sSQL = "EXECUTE Turbo_InsertAppChange app_name,@app_developer,@app_rq_num,@app_completition_date,@app_description"
Command = New SqlCommand(sSQL, Connection)
Command.Parameters.AddWithValue("@app_name", application_name.Text.ToString)
Command.Parameters.AddWithValue("@app_developer", developer_list.SelectedValue.ToString)
Command.Parameters.AddWithValue("@app_rq_num", rq_num.Text.ToString)
Command.Parameters.AddWithValue("@app_completition_date", CType(Api_calendar1.DDate, Date))
Command.Parameters.AddWithValue("@app_description", proj_desc.Text.ToString)
Try
Connection.Open()
[b]NewId = Command.ExecuteScalar[/b]
Code:
Private Shared Conn As String = Common.GetConnectionString("api_sap")
Private Shared Connection As New SqlConnection(Conn)
Private Shared Command As SqlCommand
The stored procedure is as follows:
Code:
CREATE PROCEDURE *Stored_Procedure_Name*(@app_name varchar(50),@app_developer char(3),@app_rq_num char(10),@app_completition_date datetime,
@app_description varchar(1500))
AS
INSERT INTO
*Table_Name*(app_name,app_developer,app_rq_num,app_completition_date,app_description,date_entered)
SELECT
@app_name,
@app_developer,
@app_rq_num,
CONVERT(DATETIME,@app_completition_date),
@app_description,
GETDATE()
SELECT
SCOPE_IDENTITY() as 'NewID'
Ive never used ExecuteScalar before so what am I doing wrong?
Senior Qik III,.Net,SQL Programmer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~