Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim y As Integer
For y = 0 To student.Tables(0).Rows.Count.ToString() - 1

    Dim cmd As New SqlCommand("dbo.Test", conn)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@student_id", student.Tables(0).Rows(y).Item("student_id"))
    cmd.Connection = conn
    Dim studentMark As DataSet = New DataSet()
    Dim da As SqlDataAdapter = New SqlDataAdapter("dbo.Test", conn)
    da.SelectCommand = cmd
    da.Fill(studentMark)

.
.
.

Dim fail As String = "null"


If Not studentMark.Tables(0).Rows.Count.ToString() = 0 Then
    fail = studentMark.Tables(0).Rows(0).Item("studentMark").ToString()
End If


What I have tried:

If the studentMark = fail it will return null but for the result pass it also return null and not "pass"
Posted
Updated 17-May-20 17:13pm
v4

1 solution

Your comparison is between an integer and a string; so this should always be false
"0" != 0
VB
If Not studentMark.Tables(0).Rows.Count.ToString() = 0 Then
Normally I check a DataTable like this to make sure it is not null and has content
Please note: This is C# and based on a DataTable- you will need to adjust
C#
DataTable dt = null;

// populate dt from database

if ((dt != null) && (dt.Rows.Count > 0)) {
  // get the values you need
}
 
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