Hi guys,

I am struggling to discover what the right syntax for my code would be.
I use VWebDeveloper Express 2005 and I have a web form .On the Web form I have three dropdowns that are bound through datasets and a textbox.Dropdowns are linked to display only the info relevant to the selection in the precedenig dropdown.What I want to achieve with the Text box is to display the result from a sql query, in which sql query I use the currently selected dropdown values .

However I seem to not get the syntax in the sql statement right.
Here is what I have as code in the third dropdown selected index changed event.

Protected Sub DDEntryType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDEntryType.SelectedIndexChanged
        Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB\databasename.mdb")
        Dim strSQL As String = "select max(RepPeriod) from Table where CompanyName= " & DDCompanyName.SelectedValue And  CompanyType= "&DDCompanyType.SelectedValue  and EntryType = " & DDEntryType.SelectedValue"

        Dim da As New System.Data.OleDb.OleDbDataAdapter(strSQL, conn)
        Dim ds As New Data.DataSet
        da.Fill(ds, "Table")
        tbLastEnteredRepPeriod.Text = ds.Tables(0).Rows(0)(0)
      


    End Sub

When I debug I get the following error:
BC30451: Name 'EntryType' is not declared
It`s clearly something to do with the sql statement. I just don`t really know how in different way I can get the query touse the currently selected values in the dropdown and return a single result that will be displayed in the text box.

Any help will be appreciated.

Thanks in advance

I think you just left out the "DD" before EntryType at the end of this code:

Dim strSQL As String = "select max(RepPeriod) from Table where CompanyName= " & DDCompanyName.SelectedValue And  CompanyType= "&DDCompanyType.SelectedValue  and EntryType = " & DDEntryType.SelectedValue"

so try changing it to this:

Dim strSQL As String = "select max(RepPeriod) from Table where CompanyName= " & DDCompanyName.SelectedValue And  CompanyType= "&DDCompanyType.SelectedValue  and DDEntryType = " & DDEntryType.SelectedValue"

and see if you still have a problem.

That or you just failed to declare EntryType, so you just need to declare it.

Thanks for reply crasyhorse09 , but I am not sure what do you mean
Could you please elaborate

You don't know how to declare a variable?

How do you not understand that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.