Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Dim strid As Integer
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data source=C:\Users\Dew\Documents\Shubham\ShubhamProj\StudLib.mdb")
conn.Open()
Dim cmd As OleDbCommand
cmd = conn.CreateCommand()
strid = CInt(User2nd.Text)
cmd.CommandText = "SELECT * FROM std_log where first_name='" & User1st.Text & "' and password='" & Password.Text & "' and id=' "& strid &" ';"
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()
Posted
Updated 8-Jun-14 7:43am
v3
Comments
Member 10871611 8-Jun-14 13:05pm    
An error iss coming when i add that id part in sql query, so please me in solving it...
What is that error?
phil.o 8-Jun-14 13:07pm    
And the error is?
Did you try to debug?
Member 10871611 8-Jun-14 13:12pm    
yup, it is showing this error
Data type mismatch in criteria expression.

Typo:
id=" & strid & ";"

However, you should use Parameter-Queries-in-ASP.NET-with-MS-Access[^] to prevent sql injection.
 
Share this answer
 
v3
Comments
DamithSL 8-Jun-14 13:33pm    
hi peter. i think it should be id=" & strid & ";" no need of single quote because of int value
Member 10871611 8-Jun-14 13:40pm    
Thanku
Peter Leow 8-Jun-14 13:41pm    
Thanks, you are right. missed the cint(). Amended.
Sergey Alexandrovich Kryukov 8-Jun-14 13:37pm    
Good catch, 5ed.
In Solution 2, I provided important detail on how to make it right, please see.
—SA
DamithSL 8-Jun-14 13:54pm    
sed :)
As Peter pointed out in Solution 1, this is wrong approach, because you leave your application wide open to the well know exploit called SQL injecton. This is how:
http://xkcd.com/327[^].

This is what you need to use: http://msdn.microsoft.com/en-us/library/ff648339.aspx[^].

See also: http://en.wikipedia.org/wiki/SQL_injection[^].

And please see my past answers:
EROR IN UPATE in com.ExecuteNonQuery();[^],
hi name is not displaying in name?[^].

—SA
 
Share this answer
 
Comments
Peter Leow 8-Jun-14 13:45pm    
Thanks, Sergey, for the reinforcement. 5ed!
try below code with sql parameters,
VB
cmd.CommandText = "SELECT * FROM std_log where first_name=? and password=? and id=?";
cmd.Parameters.AddWithValue("first_name", User1st.Text)
cmd.Parameters.AddWithValue("password", Password.Text)
cmd.Parameters.AddWithValue("id", strid)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()
 
Share this answer
 
Comments
Peter Leow 8-Jun-14 13:46pm    
Thanks, DamithSL. 5ed!

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