---
title: "What is the wrong with Scope_Identity?"  
description: "What is the wrong with Scope_Identity?"  
author: "Anonymous User"  
published: 2014-08-28  
updated: 2014-08-28  
canonical: https://www.mindstick.com/forum/2196/what-is-the-wrong-with-scope_identity  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# What is the wrong with Scope_Identity?

I tried milions of [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) to make [scope](https://www.mindstick.com/interview/372/what-are-the-different-scopes-for-java-variables) [identity](https://www.mindstick.com/articles/13090/icon-the-identity-of-your-brand) work. It just returns __Page !!

```
Query = "INSERT INTO seekers(name,sname,lname,status,gender,dob,major,experince,email,password,phone,valid,city) values(@name,@sname,@lname,@status,@gender,@dob,@major,@exp,@email,@password,@phone,0,@city);SELECT SCOPE_IDENTITY();";// setting up command definitionCommand = new SqlCommand(Query, Connection); // setting up command parametersCommand.Parameters.AddWithValue("email", txt_email.Text);Command.Parameters.AddWithValue("gender", lst_gender.SelectedValue);Command.Parameters.AddWithValue("status", lst_status.SelectedValue);Command.Parameters.AddWithValue("phone", long.Parse("968" + txt_phone.Text));Command.Parameters.AddWithValue("password", txt_password.Text);Command.Parameters.AddWithValue("exp", lst_exp.SelectedValue);Command.Parameters.AddWithValue("city", lst_exp.SelectedValue);Command.Parameters.AddWithValue("major", lst_major.SelectedValue);Command.Parameters.AddWithValue("name", txt_name.Text);Command.Parameters.AddWithValue("sname", txt_sname.Text);Command.Parameters.AddWithValue("lname", txt_lname.Text);Command.Parameters.AddWithValue("dob", cld_birth.SelectedDate);int ID = (int)Command.ExecuteScalar();
```

## Replies

### Reply by Sumit Kesarwani

Hi Samuel, \

Try Out Parameter as follow...

```
Query = "INSERT INTO
seekers(name,sname,lname,status,gender,dob,major,experince,email,password,phone,valid,city)
values(@name,@sname,@lname,@status,@gender,@dob,@major,@exp,@email,@password,@phone,0,@city);SET
@ID=SCOPE_IDENTITY();"//Your Parameters..SqlParameter ID=new SqlParameter();ID.Name="@ID";ID.Direction=ParameterDirection.Output;Command.Parameters.Add(ID);Command.ExecuteNonQuery();int id=(int)ID.Value;
```

or Tryb to Cast Output as follow...

```
 Query = "INSERT INTO seekers(name,sname,lname,status,gender,dob,major,experince,email,password,phone,valid,city) values(@name,@sname,@lname,@status,@gender,@dob,@major,@exp,@email,@password,@phone,0,@city);SELECT CAST(scope_identity() AS int);" int id= (Int32)Command.ExecuteScalar();
```


---

Original Source: https://www.mindstick.com/forum/2196/what-is-the-wrong-with-scope_identity

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
