Hello I need help withsetting parameters for SqlDataSource
I have a simple program. I want display date from database on MS SQLSERVER from the table USERS only for current sing on user select by his login.
I save into this variable login current user: string @.LOGIN = Context.User.Identity.Name;
I have already done with this way without SqlDataSource:
string login = Context.User.Identity.Name;SqlConnection conn1 =newSqlConnection("server=CR\\SQLEXPRESS;database=myData;integrated security=SSPI");conn1.Open();
SqlCommand cmd1 =newSqlCommand(" SELECT IN_OUT.TIME_START, IN_OUT.TIME_END, FROM IN_OUT INNER JOIN USER ON USER.USER_ID=IN_OUT.RC_USER_ID whereUSER.LOGIN=@.LOGIN", conn1);cmd1.Parameters.Add("@.LOGIN",SqlDbType.NVarChar, 50);
cmd1.Parameters[
"@.LOGIN"].Value = login;1.Parameters.Add("@.LOGIN",SqlDbType.NVarChar, 50);cmd1.Parameters[
"@.LOGIN"].Value = login;Now I don't know how to do with SqlDataSource, what I have to set in SqlDataSource1 yet
<
asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:myConnectionString %>"ProviderName="<%$ ConnectionStrings:myConnectionString.ProviderName %>"SelectCommand="SELECT IN_OUT.TIME_START, IN_OUT.TIME_END, FROM IN_OUT INNER JOIN USER ON USER.USER_ID=IN_OUT.RC_USER_ID where USER.LOGIN=@.LOGIN"></asp:SqlDataSource>Right click on the SqlDataSource in the design view, follow the wizard and write custom query with parameters.
bullpit
No comments:
Post a Comment