Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello ,

In default.aspx.cs , i defined a public variable. = my_id

And i can use this variable in my aspx page.

But i can't use in GridView DataSourceQuery.

My gridview's datasource code : ( in aspx )

SQL
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdbConnectionString %>" SelectCommand="SELECT [mus_ad], [marka], [model],  [durum] FROM [servis_kayitlari]  WHERE[kullanici_id] LIKE '<%= my_id ;%>'">
</asp:SqlDataSource>



After this datasource query , gridview comes null. What is the problem in this query ?
Posted
Comments
Give a space after WHERE. So, it will be...

SELECT [mus_ad], [marka], [model], [durum] FROM [servis_kayitlari] WHERE [kullanici_id] LIKE '<%= my_id ;%>'
kozmikadam 3-Aug-14 14:03pm    
I tried , It isn't work still.

1 solution

Try it like this
SQL
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdbConnectionString %>" SelectCommand="SELECT [mus_ad], [marka], [model],  [durum] FROM [servis_kayitlari]  WHERE[kullanici_id] LIKE @id">
</asp:SqlDataSource>

in code behind pass your my_id value to @id parameter like this
C#
SqlDataSource1.SelectParameters.Add("id", DbType.String, my_id );

Hope this works for you :-)
 
Share this answer
 
v2
Comments
kozmikadam 3-Aug-14 15:13pm    
Problem solved ! Thanks to you :)
Dilan Shaminda 3-Aug-14 15:15pm    
Nice :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900