Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim strcon As String =  ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString
    Dim con As New SqlConnection(strcon)
    Dim com As Integer = 0
    Dim suname As String

    //I got the Error that Input String Is Not if Correct Formate

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cmd As New SqlCommand("Select * from tbl_abc where uname='" + Session("mail") + "'", con)
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable()
        da.Fill(dt)
        suname = dt.Rows(0)(3).ToString()

        Dim amount As Integer
        For amount = 1 To 8
            If suname = String.IsNullOrEmpty(suname) Then
                com += 20
            Else
                com = 0
            End If
        Next amount

        MsgBox(com)
    End Sub
Posted
Updated 19-Dec-13 23:38pm
v3
Comments
TrushnaK 20-Dec-13 5:37am    
on which line you get this error.

That is some confused code.
Look at this part alone:
VB
Dim com As Integer = 0
Dim suname As String
...
        If suname = String.IsNullOrEmpty(suname) Then
Since suname is a String, and IsNullOrEmpty returns a Boolean value, the compiler with implicitly cast the Boolean to a string, so unless the name you get back from the database is "True" or "False" your code isn't going to ever add 20 to com...

You also need to look at the content of your Session variable in order to sort out the direct problem - without that you have no idea what string you are passing to SQL which is the crux of the error you have noticed.

Add some logging, use the debugger, or similar to report the value to you before it is used to build the SQL string - it's the only way you are going work out exactly what is going wrong.

And when you have sorted that out, stop doing it like that!
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
do like this..


VB
If suname = String.IsNullOrEmpty(suname) Then


VB
If   String.IsNullOrEmpty(suname) Then
 
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