Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void btnEdit_Click(object sender, RoutedEventArgs e)
      {
          try
          {
              Add_Profile ap = new Add_Profile();

              ap.txtCompanyId.Text = SetValueForText1;
              ap.txtCompanyName.Text = SetValueForText2;
              ap.txtCaption.Text = this.dataGrid.CurrentItem.ToString();
              ap.txtAddress1.Text = this.dataGrid.CurrentCell.ToString();
              ap.txtAddress2.Text = this.dataGrid.CurrentColumn.ToString();
              ap.txtMobile.Text = this.dataGrid.CurrentItem.ToString();
              ap.txtEmail.Text = this.dataGrid.CanUserAddRows.ToString();
              ap.txtGstin.Text = this.dataGrid.IsSynchronizedWithCurrentItem.Value.ToString();
              ap.txtCloudApi.Text = this.dataGrid.ItemsSource.ToString();
              ap.txtUsername.Text = this.dataGrid.CanUserResizeRows.ToString();
              ap.txtPassword.Password = this.dataGrid.CanUserResizeRows.ToString();
              ap.txtcombox.Text = this.dataGrid.CanUserResizeRows.ToString();
              ap.txtActivationKey.Text = this.dataGrid.CanUserResizeRows.ToString();
              ap.ShowDialog();
             // ap.picUserimage.Source = this.dataGrid.CurrentColumn.ToString();
              //DataRowView dataRowView = (DataRowView)((Button)e.Source).DataContext;
              //String ProductName = dataRowView[1].ToString();
              //String ProductDescription = dataRowView[2].ToString();
              //MessageBox.Show("You Clicked : " + ProductName + "\r\nDescription : " + ProductDescription);
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message.ToString());
          }
      }

      private void btnDel_Click(object sender, RoutedEventArgs e)
      {
          //if (txt.Text == "-" || lbluserid.Text == "")
          //{
          //    MessageBox.Show("You are Not able to Delete Please select item", "Question", MessageBoxButton.OK, MessageBoxImage.Warning);
          //}
          try
          {
              if (MessageBox.Show("Do you want to Delete?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
              {

              }
              DataRowView dataRowView = (DataRowView)((Button)e.Source).DataContext;
              String ProductName = dataRowView[1].ToString();
              String ProductDescription = dataRowView[2].ToString();
              MessageBox.Show("You Clicked : " + ProductName + "\r\nDescription : " + ProductDescription);
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message.ToString());
          }
      }


What I have tried:

private void BtnUpdate_Click(object sender, RoutedEventArgs e)
      {
          try
          {
              if (isValid())
              {
                  SqlConnection conn = new SqlConnection(ConnectionString);
                  conn.Open();
                  SqlCommand cmd = new SqlCommand("updateprofile_sp", conn);
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Parameters.AddWithValue("@company_id", SqlDbType.Int).Value = string.IsNullOrWhiteSpace(txtCompanyId.Text) ? DBNull.Value : (object)txtCompanyId.Text;
                  cmd.Parameters.AddWithValue("@company_name", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtCompanyName.Text) ? DBNull.Value : (object)txtCompanyName.Text;
                  cmd.Parameters.AddWithValue("@caption", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtCaption.Text) ? DBNull.Value : (object)txtCaption.Text;
                  cmd.Parameters.AddWithValue("@address1", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtAddress1.Text) ? DBNull.Value : (object)txtAddress1.Text;
                  cmd.Parameters.AddWithValue("@address2", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtAddress2.Text) ? DBNull.Value : (object)txtAddress2.Text;
                  cmd.Parameters.AddWithValue("@mobileno", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtMobile.Text) ? DBNull.Value : (object)txtMobile.Text;
                  cmd.Parameters.AddWithValue("@email", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtEmail.Text) ? DBNull.Value : (object)txtEmail.Text;
                  cmd.Parameters.AddWithValue("@gst", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtGstin.Text) ? DBNull.Value : (object)txtGstin.Text;
                  cmd.Parameters.AddWithValue("@cloudApi", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtCloudApi.Text) ? DBNull.Value : (object)txtCloudApi.Text;
                  cmd.Parameters.AddWithValue("@username", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtUsername.Text) ? DBNull.Value : (object)txtUsername.Text;
                  cmd.Parameters.AddWithValue("@password", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtPassword.Password) ? DBNull.Value : (object)txtPassword.Password;
                  cmd.Parameters.AddWithValue("@selectusertype", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtcombox.Text) ? DBNull.Value : (object)txtcombox.Text;
                  cmd.Parameters.AddWithValue("@uploadlogo", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(picUserimage.Source.ToString()) ? DBNull.Value : (object)picUserimage.Source.ToString();
                  cmd.Parameters.AddWithValue("@activationkey", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtActivationKey.Text) ? DBNull.Value : (object)txtActivationKey.Text;
                  cmd.ExecuteNonQuery();
                  conn.Close();
                  MessageBox.Show("Successfully updated", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
                  refresh();
                  New_Add_Profile nap = new New_Add_Profile();
                  nap.Show();
                  this.Hide();
              }
          }
          catch (SqlException ex)
          {
              MessageBox.Show(ex.Message);
          }
      }



Create proc updateprofile_sp
@company_id int,
@company_name varchar(100),
@caption varchar(100),
@address1 varchar(100),
@address2 varchar(100),
@mobileno varchar(100),
@email varchar(100),
@gst varchar(100),
@cloudApi varchar(100),
@username varchar(100),
@password varchar(100),
@selectusertype varchar(100),
@uploadlogo varchar(100),
@activationkey varchar(100)
AS
BEGIN
update add_profile set company_name = @company_name,caption = @caption,address1 = @address1,address2 = @address2,mobileno = @mobileno,email = @email,gst = @gst, cloudApi = @cloudApi,username = @username,password = @password,selectusertype = @selectusertype,uploadlogo = @uploadlogo,activationkey = @activationkey where company_id =@company_id
End
Posted
Updated 9-Sep-22 20:47pm
v2
Comments
OriginalGriff 10-Sep-22 1:43am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900