Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c sql:插入数据后获取自动递增id_C#_Sql_Sql Server - Fatal编程技术网

C# c sql:插入数据后获取自动递增id

C# c sql:插入数据后获取自动递增id,c#,sql,sql-server,C#,Sql,Sql Server,我正在开发一个系统,该系统使用自动递增索引作为标识符。但这给了我一个问题,因为我希望在插入后获得标识符 我在C中的内容是: string commandtxt = "INSERT INTO DATA(POINT) VALUES(@DP)"; SqlConnection conn = new SqlConnection(WebConfigurationManager.AppSettings["ConnectionInfo"].ToString()); SqlCommand sqlCommand

我正在开发一个系统,该系统使用自动递增索引作为标识符。但这给了我一个问题,因为我希望在插入后获得标识符

我在C中的内容是:

string commandtxt = "INSERT INTO DATA(POINT) VALUES(@DP)";

SqlConnection conn = new SqlConnection(WebConfigurationManager.AppSettings["ConnectionInfo"].ToString());

SqlCommand sqlCommand = new SqlCommand(commandtxt, conn);
sqlCommand.Parameters.AddWithValue("@DP", point);

conn.Open();
sqlCommand.ExecuteNonQuery();
int record id = ???? 
替换

 string commandtxt = "INSERT INTO DATA(POINT) VALUES(@DP)";
 sqlCommand.ExecuteNonQuery();

替换

 string commandtxt = "INSERT INTO DATA(POINT) VALUES(@DP)";
 sqlCommand.ExecuteNonQuery();


我相信你必须使用第二个查询:在这里从dataCheck中选择maxID-@apomene:这是一个非常糟糕的主意,在繁忙的系统中可能返回一个完全错误的值……我相信你必须使用第二个查询:在这里从dataCheck中选择maxID-@apomene:这是一个非常糟糕的主意,在繁忙的系统中可能返回一个完全错误的值系统