Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing project in vb.net but while executing the query the error occur like "No value given for one or more required parameters."
the coding for it as follows:(please give some solution)
VB
Dim cmdupdate As OleDbCommand = New OleDbCommand
    If txtuname.Text <> "" And txtadd.Text <> "" And txtphno.Text <> "" And txtemailid.Text <> "" And txtgender.Text <> "" And txtdob.Text <> "" And txtqual.Text <> "" And txtdegn.Text <> "" And txtsal.Text <> "" And txtbank.Text <> "" Then
        cmdupdate.CommandText = "UPDATE Info SET [add] = '" & txtadd.Text & "'," _
       & "[phno] = '" & txtphno.Text & "'," _
       & "[emailid] = '" & txtemailid.Text & "'," _
      & "[gender] = '" & txtgender.Text & "'," _
     & "[dob] = '" & txtdob.Text & "'," _
    & "[quali] = '" & txtqual.Text & "'," _
   & "[designation] = '" & txtdegn.Text & "', " _
   & "[salary] = '" & txtsal.Text & "' ," _
   & "[bank] = '" & txtbank.Text & "'" _
   & "WHERE name = " & cmbname.Text & ""
        con.Open()
        ' cmdupdate = New OleDbCommand(cmdupdate, con)
        cmdupdate.CommandType = CommandType.Text
        cmdupdate.Connection = con
        cmdupdate.ExecuteNonQuery()
        MsgBox(cmbname.Text = "Record updated.")
        txtuname.Text = ""
        txtadd.Text = ""
        txtbank.Text = ""
        txtdegn.Text = ""
        txtdob.Text = ""
        txtemailid.Text = ""
        txtgender.Text = ""
        txtphno.Text = ""
        txtqual.Text = ""
        txtsal.Text = ""
    Else


        MsgBox("Enter the required values:" & vbNewLine & "1. name" & vbNewLine)

    End If
    cmdupdate.Dispose()
    con.Close()
Posted
Updated 6-Dec-11 0:51am
v2

First of all, do not concatenate values to your SQL statements. Use SqlParameter[^] instead.

The problem is likely in your where condition where you don't have apostrophes around the value for name field. But as said if you use parameters you won't be facing this issue (nor SQL injections, type conversion problems etc).

Addition:
In your code, instead of
VB
& "WHERE name = " & cmbname.Text & ""

you should have
VB
& "WHERE name = '" & cmbname.Text & "'"

But as said you should use parameters instead of concatenation.
 
Share this answer
 
v2
Comments
project virus 8-Dec-11 4:34am    
Sorry I can't get it.Can you please explain it.
Wendelius 12-Dec-11 16:04pm    
Answer updated
use sqlparameter you can do easily
go through this link
may help
http://idealprogrammer.com/net-languages/code-samples/vbnet-sql-command-update-statement-source-code/[^]
 
Share this answer
 
v2
Comments
RaviRanjanKr 6-Dec-11 7:52am    
[Edited]Corrected minor Spelling Mistake[/Edited]
project virus 10-Dec-11 0:01am    
which mistake??
Abhi KA 6-Dec-11 8:41am    
k
Try using Parameters instead of concatenating the values. It is prone to SQL injection and by using parameters, you can detect which of the values is null that is producing that error.

Regards,
Eduard
 
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