Solved

SqlDataSource:   The server tag is not well formed.

Posted on 2011-03-21
6
540 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now