CODES : Beginners delight

[E] : Some more codes


Imports System.Data
Imports System.Data.SqlClient

Partial Class Adminfinance_Loaninterest
Inherits System.Web.UI.Page

Protected Sub calinterest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calinterest.Click
Dim rdr As SqlDataReader
Dim param As SqlParameter
Dim sb As New StringBuilder
sb = sb.Append("SELECT rate_of_interest,amount_received ")
sb = sb.Append("FROM new_loans_db ")
sb = sb.Append("WHERE loan_id=@loan_id")

Dim objconn As New SqlConnection
objconn.ConnectionString = ConfigurationManager.ConnectionStrings("hcms").ConnectionString
Try
objconn.Open()
Dim objcmd As New SqlCommand
objcmd.Connection = objconn
objcmd.CommandText = sb.ToString()
param = objcmd.Parameters.Add("@loan_id", SqlDbType.VarChar)
param.Value = Me.ddnloanid.SelectedItem.Text
rdr = objcmd.ExecuteReader()
If rdr.Read Then
Me.txtroi.Text = rdr(0).ToString
Me.amountreceived.Text = rdr(1).ToString

End If
rdr.Close()
Catch ex As SqlException
message.Text = "xception " + ex.Message.ToString()

objconn.Dispose()
Finally

objconn.Close()
End Try

'filling up amount of loan left

Dim rdr1 As Object
Dim param1 As SqlParameter
Dim sb1 As New StringBuilder
sb1 = sb1.Append("SELECT SUM(amount) as rdr1 ")
sb1 = sb1.Append("FROM loan_repayment_db ")
sb1 = sb1.Append("WHERE loan_id=@loan_id")
Dim objconn1 As New SqlConnection
objconn1.ConnectionString = ConfigurationManager.ConnectionStrings("hcms").ConnectionString
Try
objconn1.Open()
Dim objcmd1 As New SqlCommand
objcmd1.Connection = objconn1
objcmd1.CommandText = sb1.ToString()
param1 = objcmd1.Parameters.Add("@loan_id", SqlDbType.VarChar)
param1.Value = Me.ddnloanid.SelectedItem.Text
rdr1 = objcmd1.ExecuteScalar()
Me.txtamountpaid.Text = rdr1.ToString()

Catch ex1 As SqlException
message.Text = "xception " + ex1.Message.ToString()

objconn1.Dispose()
Finally

objconn1.Close()
End Try

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.