Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Dim conn As New OleDbConnection(" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Dew\Documents\StudentAttendance.mdb")
        conn.Open()
        Dim cmd As OleDbCommand
        cmd = conn.CreateCommand()
        If (TextBox2.Text = TextBox3.Text) Then
            cmd.CommandText = "INSERT INTO Login (Nam, Password) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "');"
            Dim i As Integer
            i = cmd.ExecuteNonQuery()
            If (i = 1) Then
                MessageBox.Show("Success!!")
            Else
                MessageBox.Show("Failure!!")
            End If
Posted
Comments
PIEBALDconsult 8-Dec-14 15:33pm    
What error? Use the debugger to examine the value of the statement.
Try the ACE engine rather than the JET engine.
Please use a parameterized statement, don't concatenate, especially values from the use. This may fix the problem.
PIEBALDconsult 8-Dec-14 15:36pm    
How is this different from your other question?
Did you not like the answers you got?
http://www.codeproject.com/Questions/783663/Whats-wrong-in-my-code?arn=0
ZurdoDev 8-Dec-14 15:58pm    
Should we guess what the error is?
Member 10871611 9-Dec-14 5:51am    
error is coming in " i=cmd.ExecuteNonQuery()" and it is insert format is wrong....

1 solution

Your approach is wrong from the very beginning. You should never create a query by concatenation of string taken from your UI. Instead, you need to use parametrized statements. Please see: http://msdn.microsoft.com/en-us/library/ff648339.aspx[^].

If you do it your way, you make your application totally vulnerable to a well-known exploit: SQL Injection. The user can write anything in the UI, including some SQL fragment. Are you getting the idea? This is how: http://xkcd.com/327[^].

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

—SA
 
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