Hello,
I have some troubles with mine code which selects data from database and show them in the GridView.

ASPX page: 1grid view, 1 button and 2 text boxes

code behind:

Protected Sub cmdVyhledat_Click() Handles cmdVyhledat.Click
        SqlDataSource1.DataBind()
        GridView1.DataBind()

    End Sub

    Protected Sub gridview_refresh() Handles SqlDataSource1.DataBinding
        If (txtCisloReklamace.Text <> "") And (txtNazevVyrobku.Text <> "") Then
            SqlDataSource1.FilterExpression = "(reklamace.cislo_rekl_zak =" & Session("jmeno") & ")"

        ElseIf (txtCisloReklamace.Text <> "") And (txtNazevVyrobku.Text = "") Then
            SqlDataSource1.FilterExpression = "(reklamace.kod_reklamace = " & txtCisloReklamace.Text & ") AND (reklamace.cislo_rekl_zak = " & Session("jmeno") & ")"

        ElseIf (txtCisloReklamace.Text = "") And (txtNazevVyrobku.Text <> "") Then
            SqlDataSource1.FilterExpression = "(vyrobky.nazev = " & txtNazevVyrobku.Text & ") AND (reklamace.cislo_rekl_zak = " & Session("jmeno") & ")"


        End If
    End Sub

I can't get rid of error:

Cannot find column [reklamace.kod_reklamace]. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.EvaluateException: Cannot find column [reklamace.kod_reklamace].

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

When I use only this code, it's all ok, but thats not what I need.

Protected Sub button1_Click() Handles Button1.Click

        SqlDataSource1.DataBind()
        GridView1.DataBind()
    End Sub

    Protected Sub gridview1_DataBinding() Handles GridView1.DataBinding
        If (TextBox1.Text = "") Then
            SqlDataSource1.FilterExpression = ""
        Else
            SqlDataSource1.FilterExpression = "([kod_reklamace] = " & TextBox1.Text & ") and ([cislo_faktury] =" & TextBox2.Text & ")"
        End If
    End Sub

Any suggestions how to fix mine problem? /Seems to be caused by INNER JOIN./

Cannot find column [reklamace.kod_reklamace].

thats your error... it cannot find that column...

either remove the reklamace. from the query and try again.

Yep I do know what does that error mean. But I don't know how to modify the code to work properly. I can't remove "reklamace." because it wouldn't be able to compare anything.
But thank you anyways

show ur query

SelectCommand= "SELECT reklamace.kod_reklamace, reklamace.kod_vyrobku, vyrobky.nazev, reklamace.cislo_rekl_zakazky, reklamace.stav, reklamace.reklamovane_mnozstvi, reklamace.jednotka, reklamace.pr, reklamace.tp, reklamace.tot, reklamace.r, reklamace.datum_pr_reklamace, reklamace.datum_pr_vzor, reklamace.no_odeslano_dne, reklamace.datum_uz_reklamace FROM reklamace INNER JOIN vyrobky ON reklamace.kod_vyrobku = vyrobky.kod_vyrobku">
If (txtCisloReklamace.Text <> "") And (txtNazevVyrobku.Text <> "") Then
            SqlDataSource1.FilterExpression = ""

        ElseIf (txtCisloReklamace.Text <> "") And (txtNazevVyrobku.Text = "") Then
            SqlDataSource1.FilterExpression = "(reklamace.kod_reklamace = " & txtCisloReklamace.Text & ")"

        ElseIf (txtCisloReklamace.Text = "") And (txtNazevVyrobku.Text <> "") Then
            SqlDataSource1.FilterExpression = "(vyrobky.nazev = '" & txtNazevVyrobku.Text & "')"

        End If

is following giving some filtering though it is not the desired one
SqlDataSource1.FilterExpression = "([kod_reklamace] = " & TextBox1.Text & ") and ([cislo_faktury] =" & TextBox2.Text & ")"
it seems pretty simple that u should check for ur desired results with removing () and also '' do some experiments with these and plz also check by removing tablename i think u dont need to mention table name

Mohtshm thx, I've combined some expressions like table_name.row with [row] and now its working correctly.

Well I've just found out that when filter contains Where xxx = xx AND yyy= yyy its not working, so Its just useful for filtering of one expression. :-(

NO actually u can use And / Or for multiple conditions

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.