Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i am new and beginner in programming
i am using Visual Studio ultimate and sql server express edition
i write a code to search phone number from the database
but i am getting error of " too large or too small value for int 32" or "conversion from string to integer is not valid"
in my database the column type is nvarchar(11) and including 0 total digits are 11
i also tried convert.toint32 and convert.toint64 but error still there.
my code is
VB
Dim cmd As New SqlClient.SqlCommand
            Dim DaLogin As New SqlClient.SqlDataAdapter
            Dim ds As New DataSet
            cmd.CommandText = "SELECT PhoneNo from [Users] WHERE PhoneNo = '" & Convert.ToInt64(txtloginuser.Text.Trim) & "'"
            Con.Open()
            cmd.Connection = Con
            DaLogin.SelectCommand = cmd
            DaLogin.Fill(ds, "0")
            Dim count = ds.Tables(0).Rows.Count
            'check weither data exist in database or not 
            If count > 0 Then
                MsgBox("User found now open the conenction", "Valid User", vbOKOnly + vbInformation)
                btnconnect.Enabled = True
            Else
                MsgBox("User not registered in database. try again or create a new account", "Invalid Phone No", vbOKOnly + vbCritical)
                txtloginuser.Text = Focused()

            End If


plz check and tell me the solution for removing this error
Posted

VB
Dim query As String = "SELECT PhoneNo from [Users] WHERE PhoneNo = @LoginUser"
   Using conn As New System.Data.SqlClient.SqlConnection("Connection String")
     Dim cmd As New System.Data.SqlClient.SqlCommand(query, conn)
     cmd.Parameters.AddWithValue("@LoginUser", SqlDbType.NVarChar).Value = txtloginuser.Text
     conn.Open()
     cmd.ExecuteNonQuery()
 
Share this answer
 
Comments
Kamran Khan 12-Jul-13 7:02am    
Now i used the code as u provided
but the error is still there

Dim query As String = "SELECT PhoneNo from [Users] WHERE PhoneNo = @LoginUser"
'Dim cmd As New System.Data.SqlClient.SqlCommand(query, Con)
'cmd.Parameters.AddWithValue("@LoginUser", SqlDbType.NVarChar).Value = txtloginuser.Text
'Con.Open()

'Dim rowaffected As Integer
'rowaffected = cmd.ExecuteNonQuery()
'If rowaffected = 1 Then
' MsgBox("User found now open the conenction", "Valid User", vbOKOnly + vbInformation)
' btnconnect.Enabled = True
'Else
' MsgBox("User not registered in database. try again or create a new account", "Phone No", vbOKOnly + vbCritical)
' txtloginuser.Text = Focused()
'End If
berrymaria 12-Jul-13 20:33pm    
Could you try to change

cmd.Parameters.AddWithValue("@LoginUser", SqlDbType.NVarChar).Value = txtloginuser.Text

to

Dim Name As String = txtloginuser.Text
cmd.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = Name;
Kamran Khan 13-Jul-13 11:50am    
i also use this
and also tried datareader in seperate code
but the error still there
sir
plz chek the datatype is correct for retrieving a phoneno from database
signup code is working fine
datatype is nvarchar(11) with not null condition
I don't see a reason why you are converting txtLoginId into int32 if the underlying datatype is nvarchar.

this should work as well.

C#
cmd.CommandText = "SELECT PhoneNo from [Users] WHERE PhoneNo = '" txtloginuser.Text.Trim & "'"
 
Share this answer
 
thanks for providing ur experience
i have tried this syed asif iqbal but same error arrises
i am trying the chimcham solution
thanks
 
Share this answer
 

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