Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim connection As OleDbConnection
        connection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\emong\Documents\Visual Studio 2008\WebSite1\Database\dbLupon.mdb")

        Dim command As OleDbCommand
        command = New OleDbCommand("UPDATE tblLUPON_C SET REGION_C = '" & lblRegion_C.Text & "', PROVINCE_C = '" & lblProvince.Text & "', CITYMUN_C = '" & cmbCityMun.SelectedValue & "', BARANGAY_C = '" & DropDownList1.SelectedValue & "',  POSITION_C = '" & cmbPosition.Text & "', COUNT_C = '" & lblUnique.Text & "', LAST_M = '" & txtLName.Text & "', FIRST_M = '" & txtFName.Text & "', MIDDLE_M = '" & txtMName.Text & "', SUFFIX_C = '" & txtSuffix.Text & "', SEX_C = '" & cmbSex.Text & "' WHERE COUNT_C = @COUNT_C", connection)
        connection.Open()
        command.ExecuteNonQuery()
        connection.Close()
        BindGrid()
    End Sub
</script>


hello.
I'm having a problem regarding the update button..
the table has 11 fields.. and I only display six of the fields.

the error was : "No value given for one or more parameters "

your answer will be great help! :)thanks!

Posted
Comments
Albin Abel 15-Feb-11 0:17am    
this problem could occur when a not null field given a null value to update. Did you check all the values you are passing in the query is not null for a not null columns. If a column is a foreign key column to another table, then it also should not be null
sevengenn 15-Feb-11 0:27am    
thanks.

but I put all the values on the textbox, but it didn't work :(

WHERE COUNT_C = @COUNT_C
You didn't declare any value for @count_c in your query.
 
Share this answer
 
Comments
sevengenn 15-Feb-11 0:27am    
thanks :)

I changed it. :)
but it has the same error :(
Is there another way to update a gridview without using the Update query?
 
Share this answer
 
Comments
Kirankumar Ballapalli 15-Feb-11 0:31am    
Hi,
Check that whether table columns allowing null values or not.
Because one of textbox values coming as empty then table column value is expecting values.
I think it will help you.
Regards,
Kiran
sevengenn 15-Feb-11 0:40am    
thanks kiran :) I will
If you want to write update query you have to use RowUpdating event of gridveiw control.
 
Share this answer
 
Comments
sevengenn 15-Feb-11 0:39am    
sir, can I used this way..

row.Cells(3).Text = txtLName.text?
VB
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim connection As OleDbConnection
        connection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\emong\Documents\Visual Studio 2008\WebSite1\Database\dbLupon.mdb")
        Dim command As OleDbCommand
        command = New OleDbCommand("UPDATE tblLUPON_C SET REGION_C = '" & lblRegion_C.Text & "', PROVINCE_C = '" & lblProvince.Text & "', CITYMUN_C = '" & cmbCityMun.SelectedValue & "', BARANGAY_C = '" & DropDownList1.SelectedValue & "',  POSITION_C = '" & cmbPosition.Text & "', COUNT_C = '" & lblUnique.Text & "', LAST_M = '" & txtLName.Text & "', FIRST_M = '" & txtFName.Text & "', MIDDLE_M = '" & txtMName.Text & "', SUFFIX_C = '" & txtSuffix.Text & "', SEX_C = '" & cmbSex.Text & "' WHERE COUNT_C = @COUNT_C", connection)
command.Parameter.AddWithValue("@COUNT_C",it's value)
        connection.Open()
        command.ExecuteNonQuery()
        connection.Close()
        BindGrid()
    End Sub
</script>



/*This Line You missed it*/
command.Parameter.AddWithValue("@COUNT_C",it's value)
 
Share this answer
 
Comments
sevengenn 15-Feb-11 1:24am    
sir, thanks! it works! :)

thanks much :) I'm so happy :) I will not check the validations :)

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