I have this sql query
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM GPS1_MAP where sta_id=" & TreeView1.SelectedNode.Value, con)
and the treeview code is here
<asp:TreeView ID="TreeView1" runat="server" AutoGenerateDataBindings="False" Font-Names="Arial"
Font-Size="Smaller" ForeColor="#C04000">
<Nodes>
<asp:TreeNode Text="Paties">
<asp:TreeNode Text="CHENAB COTTON MILLS" Value="CHENAB COTTON MILLS"></asp:TreeNode>
<asp:TreeNode Text="AJMER COTTON GINNERS" Value="AJMER COTTON GINNERS"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
But its not working with slected value of tree what may the problem?
The
Valueof your select node (eg.<asp:TreeNode Text="CHENAB COTTON MILLS" Value="CHENAB COTTON MILLS"></asp:TreeNode>) is the stringCHENAB COTTON MILLS.Therefore your SQL statement will become:
Notice that there are no quotes around
CHENAB COTTON MILLS. Your statement will therefore not be valid.You could either add quotes around the value, such as:
Or use named parameters, which is a better solution (since it prevents SQL injection attacks).