//1. Open database connection using default database try { string connectionString = TestUI.Properties.Settings.Default.UserStoreConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { bool userExists = false; con.Open(); if (userExists) { string commandText = "UPDATE [UserStore].[dbo].[user] SET Name = @Name, Surname = @Surname, @Userimage WHERE UserID = @UserID;"; SqlCommand command = new SqlCommand(commandText, con); command.Parameters.AddWithValue("@UserId", 0); MemoryStream _stream = new MemoryStream(); pcbMember.Image.Save(_stream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] _pic = _stream.ToArray(); command.Parameters.AddWithValue("@UserImage", _pic); if (txtName.Text != null) { command.Parameters.AddWithValue("@Name", txtName.Text); } if (txtSurname.Text != null) { command.Parameters.AddWithValue("@Surname", txtSurname.Text); } command.ExecuteNonQuery(); Debug.WriteLine("Existing user saved."); } else if (!userExists) { int _count = 0; string commandText = "INSERT INTO [UserStore].[dbo].[user] VALUES (Name = @Name, Surname = @Surname, UserPicture = @UserPicture, UserID = @UserID);"; SqlCommand command = new SqlCommand(commandText, con); command.Parameters.AddWithValue("@UserID", _count++); command.Parameters.AddWithValue("@Name", txtName.Text); command.Parameters.AddWithValue("@Surname", txtSurname.Text); command.Parameters.AddWithValue("@UserPicture", pcbMember.Image); command.ExecuteNonQuery(); Debug.WriteLine("New user saved."); con.Close(); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.Source); Debug.WriteLine(ex.StackTrace); } finally { }
No mapping exists from object type System.Drawing.Bitmap to a known managed provider native type. System.Data
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)