private void btnSave_Click(object sender, RoutedEventArgs e)
{
try
{
if (isValid())
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("add_profile_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(id1) ? DBNull.Value : (object)id1;
cmd.Parameters.AddWithValue("@activationkey", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtActivationKey.Text) ? DBNull.Value : (object)txtActivationKey.Text;
cmd.Parameters.AddWithValue("@createdby", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(txtCreatedby.Text) ? DBNull.Value : (object)txtCreatedby.Text;
cmd.Parameters.AddWithValue("@date", SqlDbType.Date).Value = string.IsNullOrWhiteSpace(txtDate.Text) ? DBNull.Value : (object)txtDate.Text;
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Successfully saved", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
refresh();
btnUpdate.IsEnabled = false;
New_Add_Profile nap = new New_Add_Profile();
nap.Show();
this.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
What I have tried:
CREATE TABLE add_profile
( company_id int IDENTITY(1,1) PRIMARY KEY,
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),
createdby varchar(100),
date date
)