private void btnSave_Click(object sender, RoutedEventArgs e)
{
if (txtCompanyId.Text == "")
{
MessageBox.Show("Please Enter CompanyId", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtCompanyId.Focus();
}
else if (txtCompanyName.Text == "")
{
MessageBox.Show("Please fill CompanyName", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtCompanyName.Focus();
}
else if (txtCaption.Text == "")
{
MessageBox.Show("Please fill Caption", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtCaption.Focus();
}
else if (txtAddress1.Text == "")
{
MessageBox.Show("Please fill Address1", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtAddress1.Focus();
}
else if (txtAddress2.Text == "")
{
MessageBox.Show("Please fill Address2", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtAddress2.Focus();
}
else if(txtMobile.Text == "")
{
MessageBox.Show("Please fill MobileNo", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtMobile.Focus();
}
else if(txtEmail.Text == "")
{
MessageBox.Show("Please fill Email", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtEmail.Focus();
}
else if(txtGstin.Text == "")
{
MessageBox.Show("Please fill Gstin", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtGstin.Focus();
}
else if(txtCloudApi.Text == "")
{
MessageBox.Show("Please fill CloudApi", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtCloudApi.Focus();
}
else if(txtUsername.Text == "")
{
MessageBox.Show("Please fill Username", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtUsername.Focus();
}
else if(txtPassword.ToString() == "")
{
MessageBox.Show("Please fill Password", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtPassword.Focus();
}
else if(txtActivationKey.Text == "")
{
MessageBox.Show("Please fill ActivationKey", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtActivationKey.Focus();
}
else
{
try
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("add_profile_details", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@company_id", SqlDbType.VarChar).Value = txtCompanyId;
cmd.Parameters.AddWithValue("@company_name", SqlDbType.VarChar).Value = txtCompanyName;
cmd.Parameters.AddWithValue("@caption", SqlDbType.VarChar).Value = txtCaption;
cmd.Parameters.AddWithValue("@address1", SqlDbType.VarChar).Value = txtAddress1;
cmd.Parameters.AddWithValue("@address2", SqlDbType.VarChar).Value = txtAddress2;
cmd.Parameters.AddWithValue("@mobileno", SqlDbType.VarChar).Value = txtMobile;
cmd.Parameters.AddWithValue("@email", SqlDbType.VarChar).Value = txtEmail;
cmd.Parameters.AddWithValue("@gstn", SqlDbType.VarChar).Value = txtGstin;
cmd.Parameters.AddWithValue("@username", SqlDbType.VarChar).Value = txtUsername;
cmd.Parameters.AddWithValue("@password", SqlDbType.VarChar).Value = txtPassword;
cmd.Parameters.AddWithValue("@selectusertype", SqlDbType.VarChar).Value = txtcombox;
cmd.Parameters.AddWithValue("@uploadlogo", SqlDbType.VarChar).Value = picUserimage;
cmd.Parameters.AddWithValue("@activationkey", SqlDbType.VarChar).Value = txtActivationKey;
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Successfully saved", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}
What I have tried:
try
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("add_profile_details", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@company_id", SqlDbType.VarChar).Value = txtCompanyId;
cmd.Parameters.AddWithValue("@company_name", SqlDbType.VarChar).Value = txtCompanyName;
cmd.Parameters.AddWithValue("@caption", SqlDbType.VarChar).Value = txtCaption;
cmd.Parameters.AddWithValue("@address1", SqlDbType.VarChar).Value = txtAddress1;
cmd.Parameters.AddWithValue("@address2", SqlDbType.VarChar).Value = txtAddress2;
cmd.Parameters.AddWithValue("@mobileno", SqlDbType.VarChar).Value = txtMobile;
cmd.Parameters.AddWithValue("@email", SqlDbType.VarChar).Value = txtEmail;
cmd.Parameters.AddWithValue("@gstn", SqlDbType.VarChar).Value = txtGstin;
cmd.Parameters.AddWithValue("@username", SqlDbType.VarChar).Value = txtUsername;
cmd.Parameters.AddWithValue("@password", SqlDbType.VarChar).Value = txtPassword;
cmd.Parameters.AddWithValue("@selectusertype", SqlDbType.VarChar).Value = txtcombox;
cmd.Parameters.AddWithValue("@uploadlogo", SqlDbType.VarChar).Value = picUserimage;
cmd.Parameters.AddWithValue("@activationkey", SqlDbType.VarChar).Value = txtActivationKey;
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Successfully saved", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Information);
}