Hi, Looking for a sample in C# (ASP2.0 vwd) of getting a SqlDataSource Variable (@.uNameID) into a string Variable (string uNameID)
Any help would be appreciated!
<asp:SqlDataSource ID="SqlDataSource3" runat="server" OnSelected="SqlDataSource3_Selected" ConnectionString="<%$ ConnectionStrings:testExpressConnectionString %>"
SelectCommand="SELECT userName, userPWD FROM user_test whereuserName=@.userName ">
<SelectParameters>
<asp:controlParameter Name="userName" Direction="InputOutput" Type="String" ControlID="TextBox1" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label2" runat="server" Text="Label" Width="258px"></asp:Label><asp:Button
ID="Button1" runat="server" Text="Button" /><asp:Label ID="Label3" runat="server"
Text="Label"></asp:Label>
code--
Protected Sub SqlDataSource3_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
Dim myvalue As Object = e.Command.Parameters("@.userName").Value
Label3.Text = CType(myvalue, String)
End Sub
--code
Within the selectparameter part, you can change the direction property to meet your need.
|||Thank for the reply! Is it possible to see the code in C#? I don't know VB.
|||protected void SqlDataSource3_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
object myvalue = e.Command.Parameters("@.userName").Value;
Label3.Text = ((string)(myvalue));
}
By the way, for learning purpose you can use this VB.NET to C# converter to convert some code snippets.
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
|||Thanks again for the help but I'm getting the error:
"Parameters is a Property' but is used like a method"
|||bmanmike39:
Thanks again for the help but I'm getting the error:
"Parameters is a Property' but is used like a method"
C# uses [] brackets for indexers, so it should be:
object myvalue = e.Command.Parameters["@.userName"].Value;
HTH,
Ryan
Now i'm getting the exception : "an sql Parameter with parameter name @.userName is not contained in this sql parameter collection"
Thanks for any help!
sql
No comments:
Post a Comment