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();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void btnDel_Click(object sender, RoutedEventArgs e)
{
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