0

For a class project we have to use ASP.net with VB code to do a user login, I've followed the steps pretty closely, but it seems I'm missing something. when

Dim strSQL As String = "SELECT * FROM [" & TABLE_NAME & "]" 

and

Dim dv As DataView = ds.Tables(TABLE_NAME).DefaultView 

come up "TABLE_NAME" is underlined as an undeclared object. According to my understanding this should simply pass in the name of the table I am using? I am rather confused as to what I am doing wrong here. Any help would be appreciated, here is the entire code page. I am sure I am simply making some amatuer mistake.

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

Partial Class index
    Inherits System.Web.UI.Page
    Dim con As New SqlConnection("Server = tcp:kw0ythb209.database.windows.net,1433;Database=dynamicSite;User [email protected];Password=haruhi23;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;")
    Dim da As New SqlDataAdapter()
    Dim cmd As New SqlCommand()
    Dim ds As New DataSet()


    Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        Dim strSQL As String = "SELECT * FROM [" & TABLE_NAME & "]"
        Try
            con.Open()
            da.SelectCommand = New SqlCommand(strSQL, con)
            da.Fill(ds, "dynamicSite")
            con.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        ' Get the dataview from the table
        ' alternative to: ds.Tables(0)
        ' A dataview allows sorting
        Dim dv As DataView = ds.Tables(TABLE_NAME).DefaultView

        dv.Sort = "name"
        Dim searchString As String = txtUser.Text
        Dim myIndex As Integer = dv.Find(searchString)

        If myIndex <> -1 Then

            dv.Sort = "pass"
            Dim searchString2 As String = txtPass.Text
            Dim myIndex2 As Integer = dv.Find(searchString)

            If myIndex2 <> -1 Then
                Response.Redirect("myDataView.aspx")

            End If

        Else

        End If
    End Sub
1
  • It turns out the root of the problem had to do with my connection not going through in the first place, causing nulls on down the line. Thank you everyone for your help! Commented May 3, 2015 at 20:18

3 Answers 3

1

where did you [Dim] TABLE_NAME?

I can't see this [Dim] in your code?

Sign up to request clarification or add additional context in comments.

3 Comments

Their is no point in which the example code I am working off asks to do this. If I were to [Dim] it what would I create it as? Already tried as a String.
If I use da.Fill(ds, "dynamicSite"), then I usually use ds.Tables("dynamicSite") or ds.Tables(0) instead of ds.Tables(AnotherName)
Ah, I see now, TABLE_NAME is a constant, I was simply looking at the wrong bit of code. Except now its throwing me null errors for some reason. Anyway thank you very much for your help.
0

In fill you have to map table name to your own. Adaptor will return table, table1, table2. It will not Pick name from SQL query. When u have one table you can use tables(0)

Comments

0

are you soure TABLE_NAME is evaluated in your statement?

Perhaps ds.Tables("" & TABLE_NAME & "") works.

And avoid posting your database password... ;)

Tom

1 Comment

I'm thinking you are correct and something to do with TABLE_NAME is throwing my errors. As for the password, its a practice server with IP allow and deny lists, but you are still correct on being careful with passwords.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.