0

I have created an aspx page and i am passing name to a textbox which has to display a message saying that the user exists in the database. For this i took a linq and wrote a stored procedure in it(Select username from logintest where username=@name).

I want the output of a stored procedure into a label.

Can anyone help me to solve this?

Thanks in advance

Vishal Pawar
  • 4,324
  • 4
  • 28
  • 54

2 Answers2

1

I think you'll want:

lblUsername.Text = (Select username from logintest where username=@name).FirstOrDefault().ToString();

See: http://msdn.microsoft.com/en-us/library/bb340482.aspx

And: Linq FirstOrDefault

For some more inforamtion

Community
  • 1
  • 1
RemarkLima
  • 11,639
  • 7
  • 37
  • 56
0

Try to use Any. Code example:

logintestDataContext dct = new logintestDataContext();
string userName = "john";

var logintest = (from lt in dct.logintest 
                  where lt.username.Contains(userName)
                  select lt
                 );

lblUserExist.Text = logintest.Any().ToString();

Let's explain code:

In logintestDataContext is table logintest

logintestDataContext dct = new logintestDataContext();

Using Linq, var logintest is filled from table logintest where username is like string userName (in this case john)

string userName = "john";
var logintest = (from lt in dct.logintest 
                  where lt.username.Contains(userName)
                  select lt
                 );

If there are results in logintest, label text become true. If there are no result label text become false.

lblUserExist.Text = logintest.Any().ToString();
Markweb
  • 303
  • 3
  • 6