saturation
asked on
SqlDataSource: The server tag is not well formed.
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:SQLConne ction %>"
SelectCommand="SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLogg edUser.ID & "'">
>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConne
SelectCommand="SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLogg
>
ASKER
How do I add the OnSelecting event handler? Sorry, I'm fairly new to .NET.
Modify your datasource to read:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConne ction %>"
onselecting="SqlDataSource 1_Selectin g">
Add the following method to the code behind:
protected void SqlDataSource1_Selecting(o bject sender, SqlDataSourceSelectingEven tArgs e) {
SqlDataSource1.SelectComma nd = "SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLogg edUser.ID & "'"
}
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConne
onselecting="SqlDataSource
Add the following method to the code behind:
protected void SqlDataSource1_Selecting(o
SqlDataSource1.SelectComma
}
ASKER
Is this C#? My page is VB.NET.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
%>
SelectCommand="SELECT dcca_firstname, FROM tblDCCreditApplication WHERE dcca_userid='" & DirectCast(Page, PageBaseClass).CurrentLogg
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.SelectComma