Julio Motol Julio Motol - 17 days ago 5
C# Question

Retrieve single data from a database with Linq-to-SQL

I have a table that looks like this.

CREATE TABLE [dbo].[loginInfos]
(
[loginId] INT IDENTITY (1, 1) NOT NULL,
[username] VARCHAR (50) NULL,
[password] VARCHAR (50) NULL,

PRIMARY KEY CLUSTERED ([loginId] ASC)
);


I want to get the username and compare it with a input from a textbox. It will really be a huge help.

Answer
var MyDb = new MyDb ("c:\\Data\\MyDb .mdf");

var user = =
(from u in MyDb.loginInfos
where u.username== txtUsername.Text
select u).SingleOrDefault();

// user.username