DataTable設置自增標識列的異常

public DataSet GetProviderTypeDs()
        {
            using (SqlConnection con = new SqlConnection(this.conStr))
            {
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = @"select * from ProviderType";
                con.Open();
                SqlDataAdapter ada = new SqlDataAdapter(cmd);
                ada.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                DataSet ds = new DataSet();
                ada.Fill(ds,"ProviderType");
                
                //先設置seed再設置step導致seed設置失敗,seed被設置爲Table的標識列ID最大值
                //ds.Tables[0].Columns[0].AutoIncrementSeed = -1;
                //ds.Tables[0].Columns[0].AutoIncrementStep = -1;
                
                
                ds.Tables[0].Columns[0].AutoIncrementStep = -1;
                ds.Tables[0].Columns[0].AutoIncrementSeed = -1;
                
                ds.Tables[0].Columns[0].ReadOnly = false;
                return ds;
            }
        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章