Developer : Tariq Chaudhary ; Date: March 04,2003
Tools: Visual Basic 6.0,ADO and SQL Server 2000,Crystal Reports 8.0
Inserting,Updating and Deleting database Records using ADO,SQL Server 2000,Data Grid Control
User Interface of the Application
Private Sub CmdAddNew_Click()
'for adding a new record
Adodc.Recordset.AddNew
End Sub
Private Sub CmdClear_Click()
'for clearing text controls
txtFname.Text = ""
txtLname.Text = ""
txtAddress.Text = ""
txtid.Text = ""
End Sub
Private Sub CmdDelete_Click()
'for deleting the record
Adodc.Recordset.Delete
If Not Adodc.Recordset.EOF Then
Adodc.Recordset.MoveNext
Else
Adodc.Recordset.MoveLast
End If
End Sub
Private Sub CmdExit_Click()
End
End Sub
Private Sub CmdUpdate_Click()
'for updating any record
Adodc.Recordset.Update
End Sub
OUTPUT with Data Grid Control as well as with Text Controls
top
calculating Mortgage for a House by calling a Procedure
User Interface of the Application
Option Explicit
Public Sub calculate()
Dim Lamt As Long
Dim Irate As Single
Dim time, timea As Integer
Dim dnpayment As Long 'downpayment
Dim mPayment As Single
Dim TLamt As Single
Dim APR, Interest As Single
Dim amtwInt As Single
Lamt = Val(txtLamt.Text)
Irate = Val(txtIrate.Text)
time = Val(txttime.Text)
dnpayment = Val(txtdnpayment.Text)
Interest = Lamt * Irate / 1000
amtwInt = Lamt + Interest * time 'formula for calculating total amount after interest
TLamt = amtwInt - dnpayment
timea = time * 12
mPayment = TLamt / timea 'formula to caculate monthly mortgage
MsgBox "Your monthly mortgage Payment is:$" & mPayment, vbOK
End Sub
Private Sub cmdCalulate_Click()
Call calculate ' call to a procedure in visual Basic
End Sub
Private Sub cmdClear_Click()
txtLamt.Text = "" 'this is for clearing the form entries
txtIrate.Text = ""
txttime.Text = ""
txtdnpayment.Text = ""
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
End Sub
Private Sub CmdDetails_Click()
Dim Lamt As Long
Dim Irate As Single
Dim time, timea As Integer
Dim mPayment As Single
Dim TLamt As Single
Dim Interest As Single
Dim amtwInt As Single
Dim dnpayment As Long
Lamt = Val(txtLamt.Text)
Irate = Val(txtIrate.Text)
time = Val(txttime.Text)
dnpayment = Val(txtdnpayment.Text)
Interest = Lamt * Irate / 1000
amtwInt = Lamt + Interest * time
TLamt = amtwInt - dnpayment
timea = time * 12
mPayment = TLamt / timea
Text1.Text = FormatCurrency(Lamt)
Text2.Text = Irate
Text7.Text = FormatCurrency(dnpayment)
Text3.Text = FormatCurrency(Interest)
Text4.Text = FormatNumber(time)
Text5.Text = FormatCurrency(TLamt)
Text6.Text = FormatCurrency(mPayment)
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
MsgBox " Welcome and enjoy the calculation?", vbOKOnly
End Sub
OUTPUT of the Application
Database Driven Crystal Report(database is SQL Server 2000)
top
Calling a Stored Procedure in Visual Basic using DSN connection(database is SQL Server 2000)
User Interface of the Application
top
Stored procedure created in SQL Server 2000
Create procedure sp_insert
( @f_name char(10),
@l_name char(10),
@address char(10),
@id numeric(9)
)
As
Insert into tblbiodata
values(@f_name,@l_name,@address,@id)
Option Explicit
Private Sub cmdAdd_Click()
Dim conn As New ADODB.Connection
Dim RS As Recordset
'this is for blank entries
If (Text1.Text) = "" Or (Text2.Text) = "" Or (Text3.Text) = "" Or (Text4.Text) = "" Then
MsgBox " please complete all enteries,thank you", vbExclamation
Else
conn.Execute ("sp_insert '" & Text1.Text & "','" & Text2.Text & "'," & _
" '" & Text3.Text & "'," & Text4.Text & " ")
MsgBox " A record has been inserted with id " & Text4.Text, vbOKCancel
conn.Close
Set conn = Nothing
End If
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Command1_Click()
Text1.Text = "" 'this is for clearing the text boxes
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Command2_Click()
Adodc1.Refresh
End Sub
OUTPUT
"> top
Creating and Testing ActiveX Controls Date: June 02,2003
Option Explicit
'just assigned default dimensions using Resize event handler
Private Sub UserControl_Resize()
If Height <3555 Then Height = 3555
If Width < 6570 Then Width = 6570
If Height > 4444 Then Height = 4444
End Sub
'here we are setting up a addresstext property as a string to this
'ActiveX control using Get property method
Public Property Get AddrText() As String
Dim s As String
s = txtFirst & vbCrLf
s = s & txtLast & vbCrLf
s = s & txtAddr & vbCrLf
s = s & txtAcct & vbCrLf
s = s & txtTel & vbCrLf
End Property
An Instance of an ActiveX Control(ctlUsrAddr)
Testing activeX in Visual Basic
Testing activeX in Internet Explorer
top
Importing Excel Spreadsheet to SQL Server using DTS
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
top