Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

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
0
_Esam
Asked:
_Esam
2 Solutions
 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now