Hi Friends,
I need a help, I am making a project where I have to update the class database all at once,
I made a function where some values are passing to update,
It is updating the Database as well,

But the problem is all the database is updated with the very last given value,
I want to update a specific data at a time,
A loop is giving values to this function,

I tried a SUB as well,
My code is below please do help me,

Public Function Store_All(class As String, term As String, sub1 As String, sub2 As String, sub3 As String, sub4 As String, sub5 As String, sub6 As String, sub7 As String, sub8 As String, sub9 As String) As String
If class = "Nursery" Then


If term = "1st" Then
conn.Execute ("Update Class_Nursery set subj1T1 ='" & sub1 & "',subj2T1='" & sub2 & "',subj3T1='" & sub3 & "',subj4T1='" & sub4 & "',subj5T1='" & sub5 & "',subj6T1='" & sub6 & "',subj7T1='" & sub7 & "',subj8T1='" & sub8 & "',subj9T1='" & sub9 & "';")
rec.Requery


ElseIf term = "2nd" Then
conn.Execute ("Update Class_Nursery set subj1T2 ='" & sub1 & "',subj2T2='" & sub2 & "',subj3T2='" & sub3 & "',subj4T2='" & sub4 & "',subj5T2='" & sub5 & "',subj6T2='" & sub6 & "',subj7T2='" & sub7 & "',subj8T2='" & sub8 & "',subj9T2='" & sub9 & "';")
rec.Requery


ElseIf term = "Final" Then
conn.Execute ("Update Class_Nursery set Subj1 ='" & sub1 & "',Subj2='" & sub2 & "',Subj3='" & sub3 & "',Subj4='" & sub4 & "',Subj5='" & sub5 & "',Subj6='" & sub6 & "',Subj7='" & sub7 & "',Subj8='" & sub8 & "',Subj9='" & sub9 & "';")
rec.Requery


Else
MsgBox "Select the Exam Term", vbInformation, "Term missing"
End If

End function

but where is the loop in your code ?

there is no loop in the code ....

Update.... where somefield=somevalue

You are missing the where statement and as such are setting everyrow to same value.

Good Luck

Guyz actualy this is the code of a SUBROUTIEN and i am calling this SUB via loop for sometimes and passing values to it,
values are passing accurately but the given code is not updating the database,

Update.... where somefield=somevalue

You are missing the where statement and as such are setting everyrow to same value.

Good Luck

This methodology is helping me a bit but again there is a problem...
can you please correct the following code


conn.Execute "UPDATE Class_Nursery SET [Subj1] = " & txtSbj1.Text & " WHERE(([Status] = 'Continue') AND (Session = " & txtSession.Text & ") AND (Section = " & CmbSection.Text & "));"


the above code giving the message
" No values given to one or more required parameter"

and also please write code to update more than a field of same data type using above code,

Okay, if strings you are missing the single ticks...

"UPDATE Class_Nursery SET Subj1 = [B]'[/B]" & txtSbj1.Text & "[B]'[/B] WHERE Status = 'Continue' AND Session = [B]'[/B]" & txtSession.Text & "[B]'[/B] AND Section = [B]'[/B]" & cmbSection.Txt & "[B]'[/B]"

As for updating multiple fields you have already posted the code...

SET Field1 = value1, Field2 = value2, ...

Good Luck

dear I am not updating the string here,
I am updating the integer fields,

and problem is in the where part of the clause,

Then see my post above, remove the single ticks from around the fields that are numbers and use Trim, val, cint etc. to make sure the values from the boxes are not preceeded or trailed by spaces.


Good Luck

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.