i want to develop a web base parking system
i want to retrieve the newly inserted or latest generated identity from sql server database.
after filling up and saving the new inserted data to the table
i want to display that identity value from the browser.
how may i suppose to do that.
updating/ inserting new data to database has no problem,
btw, i use stored procedure for adding data.
this is the code upon clicking button
protected void Button1_Click(object sender, EventArgs e)
{
string cs = "data source=.; database=palistuhan; integrated security=SSPI";
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("addpark", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@plate", TextBox1.Text);
cmd.Parameters.AddWithValue("@timein", TextBox1.Text);
cmd.Parameters.AddWithValue("@timeout", 0);
cmd.Parameters.AddWithValue("@cost", 0);
cmd.Parameters.AddWithValue("@date", 0);
SqlParameter outputParameter = new SqlParameter();
outputParameter.ParameterName = "@ticket";
outputParameter.SqlDbType = System.Data.SqlDbType.Int;
outputParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outputParameter);
con.Open();
cmd.ExecuteNonQuery();
}
}
i tried other code from other forum. but it seems as it returns null value.
please help me. thanks
[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]
and this is my strored procedure
USE [palistuhan]
GO
/****** Object: StoredProcedure [dbo].[addpark] Script Date: 04/12/2015 12:55:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[addpark]
@ticket int out,
@plate nchar(10),
@timein float,
@timeout float,
@date nchar(10),
@cost float
as
begin
Select @ticket = scope_identity()
insert into parking values (@plate, @timein, @timeout, @date,@cost)
return @ticket
end