?
Solved

SqlDataSource:   The server tag is not well formed.

Posted on 2011-03-21
6
Medium Priority
?
549 Views
Last Modified: 2012-06-21
I have a SQL data source and I'm trying to concatenate the logged in user with my SQL SELECT string.  I think I have the syntax wrong, though.   Can someone help?

 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
 ConnectionString="<%$ ConnectionStrings:SQLConnection %>"
 SelectCommand="SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLoggedUser.ID & "'">
>

0
Comment
Question by:saturation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:nbove
ID: 35184421
The offending line is:
SelectCommand="SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLoggedUser.ID & "'"

You are not allowed to set those values explicity inline.  
1)  Remove the "Select Command" property from your datasource.
2)  Add a "OnSelecting" event handler.
3)  In the event handler, add the following code:
SqlDataSource1.SelectCommand = "SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLoggedUser.ID & "'"
0
 

Author Comment

by:saturation
ID: 35185044
How do I add the OnSelecting event handler?   Sorry, I'm fairly new to .NET.
0
 
LVL 7

Expert Comment

by:nbove
ID: 35185101
Modify your datasource to read:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
 ConnectionString="<%$ ConnectionStrings:SQLConnection %>"
 onselecting="SqlDataSource1_Selecting">

Add the following method to the code behind:
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) {
  SqlDataSource1.SelectCommand = "SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLoggedUser.ID & "'"
}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:saturation
ID: 35185153
Is this C#?   My page is VB.NET.
0
 
LVL 7

Accepted Solution

by:
nbove earned 2000 total points
ID: 35185266
Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)) {
  SqlDataSource1.SelectCommand = "SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLoggedUser.ID & "'"
}
0
 

Author Comment

by:saturation
ID: 35186085
I get "Statement cannot appear within a method body. End of method assumed." with the code below.   What am I doing wrong?
<%

Public Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)
    SqlDataSource1.SelectCommand = "SELECT dcca_firstname FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLoggedUser.ID & "'"

End Sub

%>

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question