Repeater databinding problem (VB.NET)

Hi,
 I'm having trouble databinding to a repeater. Perhaps my syntax errors....as it complaints...
 let me know if you find it out.

 The need here is to use the session variable  and get the GO_Comments where P_ID = 1;
 Instead of declaring another variable, how is it possible to use it in the query?

               Dim p_id As String
               tv = Session("Term_Value").ToString
                Dim cn As New OleDbConnection
                Dim s As String = Server.MapPath("ADVOICE.mdb")
                cn.ConnectionString = "provider =Microsoft.Jet.OLEDB.4.0; data source = " + s

                cn.Open()
                p_id = "1"
                Dim da As New OleDbDataAdapter("SELECT G_Other_Comments.GT_ID, G_Other_Comments.P_ID, GO_Comments  FROM G_Other_Comments " & _
                "WHERE G_Other_Comments.GT_ID=" & tv & "G_Other_Comments.P_ID=" & p_id, cn)

                Dim ds As New DataSet
                da.Fill(ds, "G_Other_Comments")            >>>>>>>>>>>>This is the error line?
                TermDetails_Lea_C.DataSource = ds
                TermDetails_Lea_C.DataMember = "G_Other_Comments"
                TermDetails_Lea_C.DataBind()
                cn.Close()


It doesn't work...
It complaints about the syntax errror in the the sql query statement...
LEt me know.

Thx.
_Esam
_EsamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gadget27Commented:
I have some suggestions..

Your string is as follows>

SELECT G_Other_Comments.GT_ID, G_Other_Comments.P_ID, GO_Comments  FROM G_Other_Comments  WHERE G_Other_Comments.GT_ID=" & tv & "G_Other_Comments.P_ID=" & p_id

I would, for consistancy's sake, specify the tablename before the fieldname for all fields when selecteing them. You need to put "AND" in between your two items after WHERE as well. Also, p_id and tv looks to be Strings. If they are char or varchar or some other string value as stored in the database, you'll want to use quotes when using those variables in the querystring. Try replacing your original query string with the following>

SELECT G_Other_Comments.GT_ID, G_Other_Comments.P_ID, G_Other_Comments.GO_Comments  FROM G_Other_Comments  WHERE G_Other_Comments.GT_ID='" & tv & "' AND G_Other_Comments.P_ID='" & p_id & "'"

As part of your OleDbDataAdapter declaration, it would go like this....

Dim da As New OleDbDataAdapter("SELECT G_Other_Comments.GT_ID, G_Other_Comments.P_ID, G_Other_Comments.GO_Comments  FROM G_Other_Comments  WHERE G_Other_Comments.GT_ID='" & tv & "' AND G_Other_Comments.P_ID='" & p_id & "'", cn)

You may not need to add those single quotes around the variables, again it depends on the datatype in the database.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ddeteringCommented:
Gadget27 cought it - your where statement is wrong:
"WHERE G_Other_Comments.GT_ID=" & tv & "G_Other_Comments.P_ID=" & p_id, cn)
change to
"WHERE G_Other_Comments.GT_ID= " & tv & " AND G_Other_Comments.P_ID=" & p_id, cn)

will hopefully fix it.

Cheers,
Dietmar
0
_EsamAuthor Commented:
Thanks guys, it worked...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.