Solved

SqlDataSource:   The server tag is not well formed.

Posted on 2011-03-21
6
546 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

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

Accepted Solution

by:
nbove earned 500 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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