Showing posts with label sqldatasource. Show all posts
Showing posts with label sqldatasource. Show all posts

Tuesday, March 20, 2012

parameters.Add with SqlDataSource

Does anybody knows how to use parameters.add with SqlDataSource?

Hi,

in theSelecting event you can play around with the parameters of the DataSource control just before the actual call to the database is made.

Grz, Kris.

|||Could you please tell me about it, briefly? I'm not an advanced one in dotnet.|||

Hi,

please take a look at the code that's provided by Klaus in this post:http://forums.asp.net/t/1187969.aspx.

Grz, Kris.

|||

Thanks a lot. This will help me to solve the problem.

Monday, March 12, 2012

Parameters of SqlDataSource

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