Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
SQL
cmd.CommandText = "SELECT  distinct GLMAST.fglhead,MAINFILE.facno,max(MAINTRAN.fdate) as fdate ,max(MAINTRAN.fbalance) as fbalance  FROM MAINTRAN INNER JOIN MAINFILE ON  MAINFILE.facno like MAINTRAN.facno INNER JOIN MASTERID ON  MAINFILE.fmasterno like MASTERID.fmasterid  INNER JOIN  GLMAST ON GLMAST.fglcode like  LEFT(MAINFILE.facno,9) and   GLMAST.fglhead = '" & ComboBox2.Text & "' and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                          "where MAINTRAN.fbankcode='" & "010" & "'" & _
                                         "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                         "and MAINTRAN.fbranchcode='" & "01" & "' group by MAINFILE.facno,GLMAST.fglhead "

VB



With cmd
dr = .ExecuteReader
End With

If dr.HasRows = True Then
Do While dr.Read
presentdaybal = dr!fbalance
Loop
dr.Close()
Posted
Comments
Richard Deeming 27-Nov-14 13:57pm    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Direct after insertion, use @@identity[^] property, which returns last inserted identity value.

Do not use queries in code behind. It might be the reason of SQL Injection[^]. Use stored procedure[^] instead.

Sql Server - How to write a Stored procedure in Sql server[^]
Walkthrough: Using Only Stored Procedures (Visual Basic)[^]
 
Share this answer
 
v2
how to find latest entry in table using sql query?? okk.

if you want to select the latest entry in your sql table then use
SQL
@@Identity,@Identity_scope,@@Identity_current
(search Google for more clarification)
it works if the table has identity column(AI)

or

don't have the identity column but has a Date column(insertion Date)
SQL
select top 1 * from Table_Name order by  Date_column desc


if you have any other problem to fetching result then be more specific next time when posting any question.

you can update posted question using improve question link.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900