Sir,
I am using the following code in my vb.net while using that code it will show me syntax error.

Private Sub updateinfo()
        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Try
              con = New OleDbConnection(connectionString)

            cmd = New OleDbCommand("UPDATE [Lani] SET [First Name] = '" & txtfirst.Text & "', [Middle Name] = '" & txtmiddle.Text & "', [Last Name] = '" & txtlast.Text & "',[Company Name] = '" & txtcomp.Text & "', [Lani] Rs = '" & txtlani.Text & "',[Date] = '" & DateTimePicker1.Value.Date & "'  WHERE [Sr No] = Cint(txtid.text)", con)
            cmd.Parameters.AddWithValue("@Sr No", txtid.Text)
            cmd.Parameters.AddWithValue("@First Name", txtfirst.Text)
            cmd.Parameters.AddWithValue("@Middle Name", txtmiddle.Text)
            cmd.Parameters.AddWithValue("@Last Name", txtlast.Text)
            cmd.Parameters.AddWithValue("@Company Name", txtcomp.Text)
            cmd.Parameters.AddWithValue("@Lani Rs", txtlani.Text)
            cmd.Parameters.AddWithValue("@Lani_Date", DateTimePicker1.Value.Date)
            con.Open()

            'cmd = New OleDbCommand(strupdate, con)
            cmd.ExecuteNonQuery()

            ' Close and Clean up objects
            con.Close()
            cmd.Dispose()
            con.Dispose()

        Catch ex As Exception
            MsgBox(ex.Message.ToString)
            'updateOK = False
        End Try
    

    End Sub
End Class

While use this code in the button click event

Please help me.

Thanks in advance

Have a look,

cmd = New OleDbCommand("UPDATE [Lani] SET [First Name] =@fname,[Middle Name] = @mname,[Last Name] = @lname,[Company Name] = @cname,[Lani Rs] =@rs, [Date] =@date  WHERE [Sr No]=@srno", con)

cmd.Parameters.AddWithValue("@fname", txtfirst.Text)
cmd.Parameters.AddWithValue("@mname", txtmiddle.Text)
cmd.Parameters.AddWithValue("@lname", txtlast.Text)
cmd.Parameters.AddWithValue("@cname", txtcomp.Text)
cmd.Parameters.AddWithValue("@rs", txtlani.Text)
cmd.Parameters.AddWithValue("@date", DateTimePicker1.Value.Date)
cmd.Parameters.AddWithValue("@srno", txtid.Text)
.....

Sir,
I am using the following code in my vb.net while using that code it will show me syntax error.

Private Sub updateinfo()
        Dim cnn as string ="specify the connection string path"
        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Try
              con = New OleDbConnection(cnn)

            cmd = New OleDbCommand("UPDATE [Lani] SET [First Name] = '" & txtfirst.Text & "', [Middle Name] = '" & txtmiddle.Text & "', [Last Name] = '" & txtlast.Text & "',[Company Name] = '" & txtcomp.Text & "', [Lani] Rs = '" & txtlani.Text & "',[Date] = '" & DateTimePicker1.Value.Date & "'  WHERE [Sr No] = Cint(txtid.text)", con)
            cmd.Parameters.AddWithValue("@Sr No", txtid.Text)
            cmd.Parameters.AddWithValue("@First Name", txtfirst.Text)
            cmd.Parameters.AddWithValue("@Middle Name", txtmiddle.Text)
            cmd.Parameters.AddWithValue("@Last Name", txtlast.Text)
            cmd.Parameters.AddWithValue("@Company Name", txtcomp.Text)
            cmd.Parameters.AddWithValue("@Lani Rs", txtlani.Text)
            cmd.Parameters.AddWithValue("@Lani_Date", DateTimePicker1.Value.Date)
            con.Open()

            'cmd = New OleDbCommand(strupdate, con)
            cmd.ExecuteNonQuery()

            ' Close and Clean up objects
            con.Close()
            cmd.Dispose()
            con.Dispose()

        Catch ex As Exception
            MsgBox(ex.Message.ToString)
            'updateOK = False
        End Try
    

    End Sub
End Class

While use this code in the button click event

commented: Please read OP. -2

Sir,
While using the update code it will not update my data it will show me as it is.

I am using adatapost code

Please help me

Thank you

Sir,
I am using my code it will show me an error i.e. "No value given for one or more required parameters"

Private Sub updateinfo()

        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Try
            ' Build update statement to update Contact table with data
            ' on Textbox.

            con = New OleDbConnection(connectionString)


            cmd = New OleDbCommand("UPDATE [Lani] SET [Lani_First Name] = '" & txtfirst.Text & "', [Lani_Middle Name] = '" & txtmiddle.Text & "', [Lani_Last Name] = '" & txtlast.Text & "',[Lani_Company Name] = '" & txtcomp.Text & "', [Lani_Lani Rs] = '" & txtlani.Text & "',[Lani_Date] = '" & DateTimePicker1.Value.Date & "'  WHERE [Lani_Sr No] = Cint(txtid.text)", con)
        
            cmd.Parameters.AddWithValue("@Lani_First Name", txtfirst.Text)
            cmd.Parameters.AddWithValue("@Lani_Middle Name", txtmiddle.Text)
            cmd.Parameters.AddWithValue("@Lani_Last Name", txtlast.Text)
            cmd.Parameters.AddWithValue("@Lani_Company Name", txtcomp.Text)


            If IsNumeric(txtlani.Text) = False Then
                cmd.Parameters.AddWithValue("@Lani_Lani Rs", DBNull.Value)
            Else
                cmd.Parameters.AddWithValue("@Lani_Lani Rs", txtlani.Text)
            End If
            cmd.Parameters.AddWithValue("@Lani_Date", DateTimePicker1.Value.Date)
            cmd.Parameters.AddWithValue("@Sr No", txtid.Text)
con.Open()
                     cmd.ExecuteNonQuery()
            ' Close and Clean up objects
            con.Close()
            cmd.Dispose()
            con.Dispose()

        Catch ex As Exception
            MsgBox(ex.Message.ToString)
            'updateOK = False
        End Try
            End Sub

Please anyone help me.

Thank you

>No value given for one or more required parameters

Please verify the names of column used in commandText (Command) and in database table.

Sir,
I have check everything is correct and than still this error has been generated can I attach my project for your checking.

pLease help me

Thank you

@jallan2010.

Code in post #5 is completely incorrect. I have mentioned some correction in my post #2 and #6.

Problem in post #5 is improper use of parameters. You have two ways to go: first, do not use parametrized query and second, use it.

Code without parameter,

Private Sub updateinfo()

        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
    

       con = New OleDbConnection(connectionString)

       cmd = New OleDbCommand("UPDATE [Lani] SET [Lani_First Name] = '" & txtfirst.Text & "', [Lani_Middle Name] = '" & txtmiddle.Text & "', [Lani_Last Name] = '" & txtlast.Text & "',[Lani_Company Name] = '" & txtcomp.Text & "', [Lani_Lani Rs] = '" & txtlani.Text & "',[Lani_Date] = '" & DateTimePicker1.Value.Date & "'  WHERE [Lani_Sr No] =" &  Cint(txtid.text), con)
        
     con.Open()
     cmd.ExecuteNonQuery()
     con.Close()
     cmd.Dispose()
     con.Dispose()
End Sub

Code with parametrized query,

Private Sub updateinfo()

        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
    
        con = New OleDbConnection(connectionString)

        cmd = New OleDbCommand("UPDATE [Lani] SET [Lani_First Name] =@fname, [Lani_Middle Name] =@mname, [Lani_Last Name] = @lname,[Lani_Company Name] = @cname, [Lani_Lani Rs] = @rs,[Lani_Date] =@ldate WHERE [Lani_Sr No] = @srno", con)
        
 cmd.Parameters.AddWithValue("@fname", txtfirst.Text)
 cmd.Parameters.AddWithValue("@mname", txtmiddle.Text)
 cmd.Parameters.AddWithValue("@lname", txtlast.Text)
 cmd.Parameters.AddWithValue("@cname", txtcomp.Text)

 If IsNumeric(txtlani.Text) = False Then
     cmd.Parameters.AddWithValue("@rs", DBNull.Value)
 Else
   cmd.Parameters.AddWithValue("@rs", txtlani.Text)
 End If
 cmd.Parameters.AddWithValue("@ldate", DateTimePicker1.Value.Date)
 cmd.Parameters.AddWithValue("@srno", txtid.Text)

 con.Open()
 cmd.ExecuteNonQuery()
 con.Close()
 cmd.Dispose()
 con.Dispose()
End Sub

Sir,
First of all sorry for late reply.

I have put the code in the update subroutine in a first code you have post it will generate an error i.e. No value given for one or more required parameters.


And in the parameter code it will nothing to update in my code so please help me.

I have tried my leve best but no update at all.


Thank you.

>No value given for one or more required parameters.

Upload your database here please.

Sir,
I am enclosing my database.

Thank you

Sir,
I am using my code it will show me an error i.e. "No value given for one or more required parameters"

Private Sub updateinfo()

        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Try
            ' Build update statement to update Contact table with data
            ' on Textbox.

            con = New OleDbConnection(connectionString)


            cmd = New OleDbCommand("UPDATE [Lani] SET [Lani_First Name] = '" & txtfirst.Text & "', [Lani_Middle Name] = '" & txtmiddle.Text & "', [Lani_Last Name] = '" & txtlast.Text & "',[Lani_Company Name] = '" & txtcomp.Text & "', [Lani_Lani Rs] = '" & txtlani.Text & "',[Lani_Date] = '" & DateTimePicker1.Value.Date & "'  WHERE [Lani_Sr No] = Cint(txtid.text)", con)
        
            cmd.Parameters.AddWithValue("@Lani_First Name", txtfirst.Text)
            cmd.Parameters.AddWithValue("@Lani_Middle Name", txtmiddle.Text)
            cmd.Parameters.AddWithValue("@Lani_Last Name", txtlast.Text)
            cmd.Parameters.AddWithValue("@Lani_Company Name", txtcomp.Text)


            If IsNumeric(txtlani.Text) = False Then
                cmd.Parameters.AddWithValue("@Lani_Lani Rs", DBNull.Value)
            Else
                cmd.Parameters.AddWithValue("@Lani_Lani Rs", txtlani.Text)
            End If
            cmd.Parameters.AddWithValue("@Lani_Date", DateTimePicker1.Value.Date)
            cmd.Parameters.AddWithValue("@Sr No", txtid.Text)
con.Open()
                     cmd.ExecuteNonQuery()
            ' Close and Clean up objects
            con.Close()
            cmd.Dispose()
            con.Dispose()

        Catch ex As Exception
            MsgBox(ex.Message.ToString)
            'updateOK = False
        End Try
            End Sub

Please anyone help me.

Thank you

Please post correct column (field) names. Columns found in attached database are:

Sr No
First Name
Middle Name
Last Name
Company Name
Lani Rs
Date

Code without parameter,

Private Sub updateinfo()

        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
    

       con = New OleDbConnection(connectionString)

       cmd = New OleDbCommand("UPDATE [Lani] SET [First Name] = '" & txtfirst.Text & "', [Middle Name] = '" & txtmiddle.Text & "', [Last Name] = '" & txtlast.Text & "',[Company Name] = '" & txtcomp.Text & "', [Lani Rs] = '" & txtlani.Text & "',[Date] = '" & DateTimePicker1.Value.Date & "'  WHERE [Sr No] =" &  Cint(txtid.text), con)
        
     con.Open()
     cmd.ExecuteNonQuery()
     con.Close()
     cmd.Dispose()
     con.Dispose()
End Sub

Code with parametrized query,

Private Sub updateinfo()

        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
    
        con = New OleDbConnection(connectionString)

        cmd = New OleDbCommand("UPDATE [Lani] SET [First Name] =@fname, [Middle Name] =@mname, [Last Name] = @lname,[Company Name] = @cname, [Lani Rs] = @rs,[Date] =@ldate WHERE [Sr No] = @srno", con)
        
 cmd.Parameters.AddWithValue("@fname", txtfirst.Text)
 cmd.Parameters.AddWithValue("@mname", txtmiddle.Text)
 cmd.Parameters.AddWithValue("@lname", txtlast.Text)
 cmd.Parameters.AddWithValue("@cname", txtcomp.Text)

 If IsNumeric(txtlani.Text) = False Then
     cmd.Parameters.AddWithValue("@rs", DBNull.Value)
 Else
   cmd.Parameters.AddWithValue("@rs", txtlani.Text)
 End If
 cmd.Parameters.AddWithValue("@ldate", DateTimePicker1.Value.Date)
 cmd.Parameters.AddWithValue("@srno", txtid.Text)

 con.Open()
 cmd.ExecuteNonQuery()
 con.Close()
 cmd.Dispose()
 con.Dispose()
End Sub

Sir,

I am using without parameter code

It will show me an error i.e. data type mismatch in criteria expressions.

I think i will better to enclose my project .

What do you think sir please reply


Thank you

Sir,
I am enclosing my project please help me.

I am appreciate your reply

Please help me.

Thank you

Have a look at code in your uploaded project of updateInfor() method,

You are adding @rs parameter twice.

cmd = New OleDbCommand("UPDATE [Lani] SET [First Name] = @fname, [Middle Name] = @mname, [Last Name] = @lname,[Company Name] = @cname, [Lani Rs] = @rs,[Date] = @ldate WHERE [Sr No] = @srno", con)
            cmd.Parameters.AddWithValue("@fname", txtfirst.Text)
            cmd.Parameters.AddWithValue("@mname", txtmiddle.Text)
            cmd.Parameters.AddWithValue("@lname", txtlast.Text)
            cmd.Parameters.AddWithValue("@cname", txtcomp.Text)
            cmd.Parameters.AddWithValue("@rs", txtlani.Text)

            If IsNumeric(txtlani.Text) = False Then
                cmd.Parameters.AddWithValue("@rs", DBNull.Value)
            Else
                cmd.Parameters.AddWithValue("@rs", txtlani.Text)
            End If
            cmd.Parameters.AddWithValue("@ldate", DateTimePicker1.Value.Date)

            cmd.Parameters.AddWithValue("@srno", txtid.Text)

Correct code is,

Private Sub updateinfo()
        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        con = New OleDbConnection(connectionString)

        cmd = New OleDbCommand("UPDATE [Lani] SET [First Name] = @fname, [Middle Name] = @mname, [Last Name] = @lname,[Company Name] = @cname, [Lani Rs] = @rs,[Date] = @ldate WHERE [Sr No] = @srno", con)
        cmd.Parameters.AddWithValue("@fname", txtfirst.Text)
        cmd.Parameters.AddWithValue("@mname", txtmiddle.Text)
        cmd.Parameters.AddWithValue("@lname", txtlast.Text)
        cmd.Parameters.AddWithValue("@cname", txtcomp.Text)
        cmd.Parameters.AddWithValue("@rs", txtlani.Text)
 
        cmd.Parameters.AddWithValue("@ldate", DateTimePicker1.Value.Date)

        cmd.Parameters.AddWithValue("@srno", txtid.Text)

        con.Open()

        cmd.ExecuteNonQuery()

        con.Close()
        cmd.Dispose()
        con.Dispose()
    End Sub

Sir,

It is general question how to improve my logic in programming if you have link so please sent me on my email-id <<Email Snipped>>.


Thank you so much sir,

>It is general question how to improve my logic in programming if you have link so please sent me.

Improve your understanding. You can improve your mind by reading programming/non-programming books/blogs/forum threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.