Hi daniwebians

I have created a table in sql server called "report" and it has 3 columns "reportname","reportfile" and "reportflag". the report flag has only two values 1 and 0,if the value is 1 this means the textbox on the form will be enable. I have managed to dispaly the reportname in the listbox and by the way this table is on the other network and i have also managed to connect to the sql database over the network. I have categorized my problem for easy understanding on my part and for the solution.

1.Connect to the server and display the reportname on the report table in the listbox of my form.
2.Select the reportname on the listbox and get the reportfilename and checked if the reportflag is equal to 1 or not.
3. Assign the result to a variable.

The category 1 is already solved but the category 2 and 3 is still on the part of my analysis since i am not to familiar to vb.net, I have been searching for solutions over the internet, unfortunately i was not able to find any answers.

My question is how can i compare it and assign it to a variable given by the result of the compare string using sql since i am using sql. should i still used the dataadapter or datareader and how can i assign it to a variable

Please give me some advice or reference to study. thanks in advance.

best regards

I don't know what method you are using to interface to the database but it could be done like

    Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

        Dim lbx As ListBox = sender

        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Dim rdr As SqlDataReader

        Dim reportfile As String
        Dim reportflag As Boolean

        con.ConnectionString = "Data Source=.\SQLEXPRESS;Initial Catalog=myDB;Integrated Security=True"
        con.Open()

        cmd.Connection = con
        cmd.CommandText = "SELECT reportfile, reportflag FROM report " & _
                          " WHERE reportname = '" & lbx.Text & "'"

        rdr = cmd.ExecuteReader()

        If rdr.HasRows Then
            rdr.Read()
            reportfile = rdr.GetString(0)
            reportflag = rdr.GetBoolean(1)
        End If

        rdr.Close()
        con.Close()

    End Sub

You can add any code after line 24 to do what you want with reportfile and reportflag. You would also have to change the ConnectionString accordingly.

Edited 4 Years Ago by Reverend Jim

This question has already been answered. Start a new discussion instead.