-
Oct 5th, 2022, 09:05 PM
#1
Thread Starter
New Member
conversion from string to integer is not valid
Please can u help me out here cos i have been trying and keep getting error when i try to update with try catch saying conversion from string to integer is not valid
Code:
Try
SqlQuery = "Update tb_login set FullName = @FullName, Email = @Email, Gender = @Gender, DoB = @DoB, Username = @Username, Password = @Password, RoleType = @RoleType, Status = @Status, Image = @Image WHERE ID = '" & txtID.Text & "'"
cmd = New MySqlCommand(SqlQuery, conn)
'cmd.Parameters.AddWithValue("@ID", txtID.Text)
cmd.Parameters.AddWithValue("@FullName", txtFullName.Text)
cmd.Parameters.AddWithValue("@Email", txtUserEmail.Text)
cmd.Parameters.AddWithValue("@Gender", cboGender.Text)
cmd.Parameters.AddWithValue("@DoB", dtpUserDOB.Value)
cmd.Parameters.AddWithValue("@Username", txtUserName.Text)
cmd.Parameters.AddWithValue("@Password", txtConfirmP.Text)
cmd.Parameters.AddWithValue("@RoleType", cboRole.Text)
cmd.Parameters.AddWithValue("@Status", cboStatus.Text)
'cmd.Parameters.AddWithValue("@Image", arrImage)
Dim mstream As New System.IO.MemoryStream()
pboPic.Image.Save(mstream, pboPic.Image.RawFormat)
arrImage = mstream.GetBuffer()
Dim FileSize As UInt32
FileSize = mstream.Length
Dim para As New MySqlParameter("@Image", SqlDbType.Image)
para.Value = arrImage
cmd.Parameters.Add(para)
Dim r As Integer
r = cmd.ExecuteNonQuery()
If r > 1 Then
MsgBox("Records of " & txtFullName.Text & " UPDATED Successfully", MsgBoxStyle.Information)
txtFullName.Clear()
txtUserEmail.Clear()
cboGender.Text = String.Empty
dtpUserDOB.ResetText()
txtUserName.Clear()
txtPassword.Clear()
txtConfirmP.Clear()
cboRole.Text = String.Empty
cboStatus.Text = String.Empty
pboPic.Image = Nothing
Else
MsgBox("Records of " & txtFullName.Text & " is not UPDATED", MsgBoxStyle.Information)
End If
cmd.Parameters.Clear()
Catch ex As Exception
MsgBox(ex.Message, "Unable to Save", vbExclamation)
End Try
Last edited by Shaggy Hiker; Oct 6th, 2022 at 09:16 AM.
Reason: Added CODE tags.
-
Oct 6th, 2022, 03:40 AM
#2
Re: conversion from string to integer is not valid
Please don't post unformatted code snippets. They are much harder to read, especially as they get longer.
Code:
Try
SqlQuery = "Update tb_login set FullName = @FullName, Email = @Email, Gender = @Gender, DoB = @DoB, Username = @Username, Password = @Password, RoleType = @RoleType, Status = @Status, Image = @Image WHERE ID = '" & txtID.Text & "'"
cmd = New MySqlCommand(SqlQuery, conn)
'cmd.Parameters.AddWithValue("@ID", txtID.Text)
cmd.Parameters.AddWithValue("@FullName", txtFullName.Text)
cmd.Parameters.AddWithValue("@Email", txtUserEmail.Text)
cmd.Parameters.AddWithValue("@Gender", cboGender.Text)
cmd.Parameters.AddWithValue("@DoB", dtpUserDOB.Value)
cmd.Parameters.AddWithValue("@Username", txtUserName.Text)
cmd.Parameters.AddWithValue("@Password", txtConfirmP.Text)
cmd.Parameters.AddWithValue("@RoleType", cboRole.Text)
cmd.Parameters.AddWithValue("@Status", cboStatus.Text)
'cmd.Parameters.AddWithValue("@Image", arrImage)
Dim mstream As New System.IO.MemoryStream()
pboPic.Image.Save(mstream, pboPic.Image.RawFormat)
arrImage = mstream.GetBuffer()
Dim FileSize As UInt32
FileSize = mstream.Length
Dim para As New MySqlParameter("@Image", SqlDbType.Image)
para.Value = arrImage
cmd.Parameters.Add(para)
Dim r As Integer
r = cmd.ExecuteNonQuery()
If r > 1 Then
MsgBox("Records of " & txtFullName.Text & " UPDATED Successfully", MsgBoxStyle.Information)
txtFullName.Clear()
txtUserEmail.Clear()
cboGender.Text = String.Empty
dtpUserDOB.ResetText()
txtUserName.Clear()
txtPassword.Clear()
txtConfirmP.Clear()
cboRole.Text = String.Empty
cboStatus.Text = String.Empty
pboPic.Image = Nothing
Else
MsgBox("Records of " & txtFullName.Text & " is not UPDATED", MsgBoxStyle.Information)
End If
cmd.Parameters.Clear()
Catch ex As Exception
MsgBox(ex.Message, "Unable to Save", vbExclamation)
End Try
Also, please don't leave wads of leading whitespace on your code. You can hold down the Alt key as you select in VS to select an arbitrary block of code, trimming the unnecessary leading whitespace and keeping only what's required for indenting.
-
Oct 6th, 2022, 03:44 AM
#3
Re: conversion from string to integer is not valid
As for the issue, where is the exception thrown? You need to provide ALL the relevant information and where an exception is thrown is obviously relevant. We shouldn't have to guess or work out stuff that you already know. Also, what string is invalid? You should know and be able to tell us. If you don't know then it means that you haven't actually made any attempt to solve the issue yourself before posting here. You need to do what you can for yourself first and looking to see what data is invalid is the least of that. If you still can't work out the problem, at least you can give us all the relevant information.
-
Oct 6th, 2022, 04:28 AM
#4
Re: conversion from string to integer is not valid
Start by taking out the Try - Catch - End Try block so at least you will see which line is causing the error.
-
Oct 6th, 2022, 04:31 AM
#5
Re: conversion from string to integer is not valid
*sigh*
Code:
SqlQuery = "Update tb_login set FullName = @FullName, Email = @Email, Gender = @Gender, DoB = @DoB, Username = @Username, Password = @Password, RoleType = @RoleType, Status = @Status, Image = @Image
WHERE ID = '" & txtID.Text & "'"
cmd = New MySqlCommand(SqlQuery, conn)
'This one is commented out. Why?
'cmd.Parameters.AddWithValue("@ID", txtID.Text)
Is ID in your DB-Table a String or Integer?
is txtID.text empty or has it a valid Value?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|