C# 始终自动递增ID为0

C# 始终自动递增ID为0,c#,sql-server,model-view-controller,C#,Sql Server,Model View Controller,我有一个页面到一个用户来输入诸如姓名、地址和电话号码之类的信息,但是我在查看页面的页面中隐藏了UserID列。因此我的页面包含以下信息。 Name=Textbox, 地址=文本框 当我运行页面时 在两个文本框上方显示 输入值后 名称=xxxxx 地址=加利福尼亚 当我调试时单击按钮时,显示的用户id为0 using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["infinity"].C

我有一个页面到一个用户来输入诸如姓名、地址和电话号码之类的信息,但是我在查看页面的页面中隐藏了UserID列。因此我的页面包含以下信息。 Name=Textbox, 地址=文本框

当我运行页面时 在两个文本框上方显示 输入值后 名称=xxxxx 地址=加利福尼亚 当我调试时单击按钮时,显示的用户id为0

using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["infinity"].ConnectionString))
        {
            List<Plantation> studentlist = new List<Plantation>();
            using (SqlCommand cmd = new SqlCommand("sproc_UpdatePlantation ", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@PlantationID", viewPlantationModel.PlantationID); // here always 0
使用(SqlConnection con=newsqlconnection(ConfigurationManager.ConnectionStrings[“无限”].ConnectionString))
{
List studentlist=新列表();
使用(SqlCommand cmd=newsqlcommand(“存储过程更新安装”,con))
{
cmd.CommandType=CommandType.storedProcess;
cmd.Parameters.AddWithValue(“@PlantationID”,viewPlantationModel.PlantationID);//此处始终为0

如何解决这个问题我没有在使用mvc视图的网页中向用户显示用户id,但我在数据库中有一列显示自动增量id,看起来您没有在视图中使用id的隐藏变量,所以请在视图中编写以下代码

@Html.HiddenFor(c => c.ID) 

欢迎使用SO!不幸的是,我认为没有人能够用给出的信息回答这个问题。请参阅以获取有关如何吸引有用答案的提示。不清楚您要求的是什么。是否需要数据库生成并自动递增用户标识号?