Saturday 15 June 2013

Coding to Send Email on a Button Click With and Without attachment

 
Private Sub sendbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendbutton.Click
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        Try
            Dim mail, atchmail As New MailMessage
            mail.Subject = subjecttextbox.Text
            mail.To.Add(totextbox.Text)
            mail.From = New MailAddress(usernametextbox.Text)
            mail.Body = bodytextbox.Text
            If attachmenttextbox.Text <> "" Then 'If attachment is there than this code will be executed
                Dim attachment As System.Net.Mail.Attachment
                attachment = New System.Net.Mail.Attachment(attachmenttextbox.Text)
                mail.Attachments.Add(attachment)

                Dim smtp As New SmtpClient("smtp.gmail.com")
                smtp.EnableSsl = True
                smtp.Credentials = New System.Net.NetworkCredential(usernametextbox.Text, passwordtextbox.Text)
                smtp.Port = "587"
                smtp.Send(mail)
            Else 'If there is no attachment than this code is executed
                Dim smtp As New SmtpClient("smtp.gmail.com")
                smtp.EnableSsl = True
                smtp.Credentials = New System.Net.NetworkCredential(usernametextbox.Text, passwordtextbox.Text)
                smtp.Port = "587"
                smtp.Send(mail)
            End If

            MsgBox("Message Sent Successfully", MsgBoxStyle.Information)
            totextbox.Clear()
            subjecttextbox.Clear()
            bodytextbox.Clear()
            attachmenttextbox.Clear()
            usernametextbox.Text = "sample_email@gmail.com"
            passwordtextbox.Clear()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        

    End Sub

Crystal Report Chart Expert showing Count instead of Sum

Sometimes in crystal report while showing a bar chart if we want to show the sum or average of some values other than count, the chart expert may not show you all the summary option like average, sum, mode etc. Though the coding is correct and no error is displayed its just that the chart expert doesn't show the summary option other than count or distinct count. This is because the value for which you want to display average or sum is not of desired data-type, for example, if we want to display marks on the change of roll no. than marks should be of data-type like integer or double rather than choosing the data-type like string. So just check the data-type to get rid of this problem.
Happy coding :)