Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am Trying to make a system that counts the number of enrollees
My Code actually computes the values of the textboxes but when i press the save button it says

Conversion from string "Update requires a valid UpdateCo" to type 'Integer' is not valid.

Can anyone please help me how

What I have tried:

This is my code the Add Button
Dim con As New System.Data.OleDb.OleDbConnection("Provider = Microsoft.jet.OleDB.4.0;Data Source =  " & Application.StartupPath & "\planning.mdb;")
Try
    ElementaryBindingSource.EndEdit()
    ElementaryTableAdapter.Update(PlanningDataSet.Elementary)
    Me.Update()
    MessageBox.Show(" Data Added Successfully")
Catch ex As Exception
    Error (ex.Message)
End Try
And this is for the compute button
Dim ans As Integer
ans = TMTextBox.Text
TMTextBox.Text = Val(KMTextBox.Text) + Val(G1MTextBox.Text) + Val(G2MTextBox.Text) + Val(G3MTextBox.Text) + Val(G4MTextBox.Text) + Val(G5MTextBox.Text) + Val(G6MTextBox.Text)
Posted
Updated 9-Aug-21 20:19pm
v2
Comments
Sandeep Mewara 5-Aug-20 5:32am    
Error is not clear on what you got. Can you share the exact error?

Seems data type conversion error with your code.
Beginner213456 5-Aug-20 19:53pm    
Conversion from string "Update requires a valid UpdateCo" to type 'Integer' is not valid.

that is the exact error that pops up
Maciej Los 5-Aug-20 5:55am    
Dim ans As Integer
ans = TMTextBox.Text 'string is not integer!

1 solution

An error occurs in this line:

VB.NET
Dim ans As Integer
ans = TMTextBox.Text 'string is not integer!


Please, do not use Val[^] to get integer value, because it's vb specific.
Rather than it, use: Int32.Parse Method (System) | Microsoft Docs[^] or Int32.TryParse Method (System) | Microsoft Docs[^]

[EDIT]
Usage:
vb.next
Dim tboxes As List(Of TextBox) = New List(Of TextBox) With {KMTextBox, G1MTextBox, G2MTextBox, G3MTextBox, G4MTextBox, G5MTextBox, G6MTextBox}

Dim result As Integer = 0
For Each txt As TextBox In tboxes
	Dim tmpVal As Integer = 0
	Dim success As Boolean = Int32.TryParse(txt.Text, tmpVal)
	If success Then result += tmpVal
Next
TMTextBox.Text = result.ToString()
 
Share this answer
 
v2
Comments
Beginner213456 5-Aug-20 20:02pm    
Can you please give me an example

i tried

KTTextBox.Text = int32.typeparse(kmtextbox.Text) + int32.tryparse(kftextbox.Text)

but it says

Overload resolution failed because no accessible 'TryParse' accepts this number of arguments.
Sandeep Mewara 6-Aug-20 1:21am    
Seems you did not open the reference documents at all. TryParse take two arguments, it outs the value and returns boolean if success or not.
Dim number As Integer
Dim success As Boolean = Int32.TryParse(value, number)
Sandeep Mewara 6-Aug-20 1:21am    
+5
Maciej Los 6-Aug-20 2:19am    
Thank you, Sandeep.

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