Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class User
- {
- public int UserID { get; set; }
- public string FirstName {get; set;}
- public string LastName {get;set;}
- public bool? Active {get;set;}
- public int? Age { get; set; }
- public string Sex { get; set; }
- }
- // Initialize just two fields and leave the other to their defaults
- // (null for both strings and nullable ints)
- User u = new User();
- u.UserID = 1;
- u.FirstName = "Steve";
- bool ok = UpdateUser(u);
- if(ok) ......
- public UpdateUser(User info)
- {
- using(SqlConnection cnn = new SqlConnection(@"Data Source=(LOCAL);
- Initial Catalog=TestDB;
- Integrated Security=True;"))
- {
- cnn.Open();
- // Prepare the parameters to pass to the Dapper Execute
- var pms = new
- {
- UserID = info.UserID
- FirstName = info.FirstName,
- LastName = info.LastName, // <- from here all is null
- Active = info.Active,
- Age = info.Age,
- Sex = info.Sex
- };
- int rows = cnn.Execute(@"UPDATE [UserTable]
- SET FirstName= @FirstName,
- LastName = @LastName,
- Active = @Active,
- Age = @Age,
- Sex = @Sex
- WHERE UserID = @UserID",
- pms);
- return rows != 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement