Sending Mail using SmtpClient
October 29, 2007 at 9:37 am | In Dot Net | Leave a CommentImports System.Net.Mail
Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRegister.Click
Dim smtpClient As New SmtpClient
Dim message As New MailMessage
Dim fromAddress As New MailAddress(host site mail address)
Dim toAddress As New MailAddress(receiver mail address)
Try
‘You can specify the host name or ipaddress of your server
‘ Default in IIS will be localhost
smtpClient.Host = “localhost”
‘Default port will be 25
smtpClient.Port = 25
‘From address will be given as a MailAddress Object
message.From = fromAddress
‘To address collection of MailAddress
message.To.Add(toAddress)
message.Subject = “Feedback”
‘// CC and BCC optional
‘// MailAddressCollection class is used to send the email to various users
‘// You can specify Address as new MailAddress(“admin1@yoursite.com”)
message.CC.Add(“admin1@yoursite.com”);
message.CC.Add(“admin2@yoursite.com”);
‘// You can specify Address directly as string
message.Bcc.Add(new MailAddress(“admin3@yoursite.com”));
message.Bcc.Add(new MailAddress(“admin4@yoursite.com”));
‘Body can be Html or text format
‘Specify true if it is html message
message.IsBodyHtml = False
‘Message body content
message.Body = [message as string]
‘Send SMTP mail
smtpClient.Send(message)
Response.Write(“alert(‘Email successfully
sent.’);”)
Catch ex As Exception
Response.Write(“alert(‘Email sent fail.’);”)
End Try
End Sub
Use of Date time
October 26, 2007 at 12:43 pm | In SQL Server | Leave a CommentTo display date in format : dd/mm/yyyy
convert(varchar(12),[field name],103)
To get records between two dates use following syntax in where condition.
Note : 1) Assuming that field type is varchar in database table.
2) From date & to date variables are in date format.
Convert(datetime,Convert(varchar(12),[field name])) between Convert(datetime,[from date variable] ) and Convert(datetime,[to date variable])
Using Cursor – Basic syntax
October 26, 2007 at 12:29 pm | In SQL Server | Leave a CommentUsing Cursor – Basic syntax
DECLARE [cursor name] CURSOR
FOR
[SELECT query ]
OPEN [cursor name]
[DECLARE variables]
FETCH NEXT FROM [cursor name] INTO [variable list]
WHILE(@@FETCH_STATUS -1)
BEGIN
IF(@@FETCH_STATUS -2)
BEGIN
[Insert/Update statements]
END
FETCH NEXT FROM [cursor name] TO[variable list]
END
CLOSE [cursor name]
DEALLOCATE [cursor name]
Use File Upload control with read only text box.
October 24, 2007 at 12:44 pm | In Dot Net | 1 CommentQuery :
File Upload Control read only so that no one can
edit file upload text box.
User can select files only with Browse button.
Solution :
Use javascript for this purpose
<input id=”File1″ type=”file” onkeypress=”javascript: return false;” />
Calling Crystal report viewer in dot net
October 23, 2007 at 12:57 pm | In Dot Net | Leave a CommentUsing Crystal report in dot net
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Dim intCounter As Integer
Dim intCounter1 As Integer
‘Crystal Report’s report document object
Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
‘object of table Log on info of Crystal report
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
‘Sub report object of crystal report.
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
‘Sub report document of crystal report.
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim index As Integer
‘Load the report
objReport.Load()
‘Set the connection information
ConInfo.ConnectionInfo.UserID =
ConInfo.ConnectionInfo.Password =
ConInfo.ConnectionInfo.ServerName =
ConInfo.ConnectionInfo.DatabaseName =
For intCounter = 0 To objReport.Database.Tables.Count – 1
objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
Next
‘ Loop through each section on the report then look
‘ through each object in the section
‘ if the object is a subreport, then apply logon info
‘ on each table of that sub report
For index = 0 to objReport.ReportDefinition.Sections.Count – 1
For intCounter = 0 To _
objReport.ReportDefinition.Sections(index).ReportObjects.Count – 1
With objReport.ReportDefinition.Sections(index)
If .ReportObjects(intCounter).Kind = _
CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
mySubReportObject = CType(.ReportObjects(intCounter), _
CrystalDecisions.CrystalReports.Engine.SubreportObject)
mySubRepDoc = _
mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count – 1
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo( _
ConInfo)
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo( _
ConInfo)
Next
End If
End With
Next
Next
‘If there is a selection formula
If sSelectionFormula.Length > 0 Then
objReport.RecordSelectionFormula = sSelectionFormula
End If
‘Formula fields in string with key-value pair.
‘Key-value separated by comma and forumlas are seperated by |
If sFormulas.Trim() “” Then
Dim sFormulaWithValues() As String = Split(sFormulas, “|”)
Dim i As Integer
For i = 0 To UBound(sFormulaWithValues)
Dim sFormulaValue() As String = Split(sFormulaWithValues(i), “,”)
objReport.DataDefinition.FormulaFields(sFormulaValue(0)).Text = sFormulaValue(1)
Next i
End If
‘Report file name
sFileName = AppDomain.CurrentDomain.BaseDirectory & “reports\” & sFileName
CrystalReportViewer1.ReportSource = objReport
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.DataBind()
‘Toolbar
CrystalReportViewer1.DisplayToolbar = True
‘Group tree
CrystalReportViewer1.DisplayGroupTree = False
Split() function
October 23, 2007 at 7:31 am | In Crystal Report | 2 CommentsUsing split() function with array in crystal report
// 1) To return single element value in string
local stringVar array ;
local stringVar returnValue;
:=Split({},’;'); // Split(,delimeter);
returnValue:=[0];
// 2) To return all elements in string
local numbervar asize := ubound();
local numbervar x;
local stringvar returnValue:=”";
for x := 1 to asize do
(
returnValue := returnValue & [x] & ” “;
);
returnValue;
Hello world!
October 22, 2007 at 7:07 am | In Uncategorized | 1 CommentWelcome to WordPress.com. This is your first post. Edit or delete it and start blogging!
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.