Julio Motol Julio Motol - 1 year ago 76
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,


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

Answer Source
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download