我正在尝试使用excel文件将用户从一个sql数据库上传到其他sql数据库,但我无法在应用程序的identityuser表中上传用户。
这是我的代码,如果我错了,请纠正我
SqlConnection sqlc = new SqlConnection();
sqlc.ConnectionString = @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Planetskool-20150303080110.mdf;Initial Catalog=aspnet-Planetskool-20150303080110;Integrated Security=True";
SqlCommand cmd1 = new SqlCommand("INSERT INTO IdentityUser (Id,UserName,Email,PasswordHash,SecurityStamp,Discriminator) VALUES(@Id,@UserName,@Email,@PasswordHash,@SecurityStamp,@Discriminator)", sqlc);//@OB_ID is indentity primary key
cmd1.Parameters.Add("@Id", SqlDbType.VarChar).Value = (ds.Tables[0].Rows[j]["Id"]);
cmd1.Parameters.Add("@UserName", SqlDbType.VarChar).Value = (ds.Tables[0].Rows[j]["UserName"]).ToString();
cmd1.Parameters.Add("@Email", SqlDbType.VarChar).Value = (ds.Tables[0].Rows[j]["Email"]).ToString();
cmd1.Parameters.Add("@PasswordHash", SqlDbType.VarChar).Value = (ds.Tables[0].Rows[j]["PasswordHash"]).ToString();
cmd1.Parameters.Add("@SecurityStamp", SqlDbType.VarChar).Value = (ds.Tables[0].Rows[j]["SecurityStamp"]).ToString();
cmd1.Parameters.Add("@Discriminator", SqlDbType.VarChar).Value = "ApplicationUser";
sqlc.Open();
cmd1.ExecuteNonQuery();
sqlc.Close();
当我调试数据库时,它显示id == null,因此有任何解决此问题的方法