Click here to Skip to main content
15,883,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please discribe with example how to populate text box with data from data base with linq to sql in c#?
Posted
Comments
Chamika Sandamal 27-Mar-13 2:44am    
Better you try something before just putting questions
Prasad Khandekar 27-Mar-13 2:48am    
Just search on MSDN library. You can find many examples in the LINQ documentation.

1 solution

You can try following code sample,
XML
DataClasses1DataContext dc = new DataClasses1DataContext();
var q = (from a in dc.GetTable<Order>()
        where a.Number== number
        select a).SingleOrDefault();
textBox1.Text= q.Something;
 
Share this answer
 
Comments
Hodamdi 27-Mar-13 4:28am    
tanx for your replay but i have 2 text box and i want to type code in txtEstateCode and after pressing enter key i should see Estatename in another txtEstatename i wrote bellow code :

private void txtEstateCode_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{

txtEstateName.Text = GiveEstateName(txtEstateCode.Text);
}
}
public dynamic GiveEstateName(string EstateCode)
{
using (DataLink.AsamLinqDataContext Dc = new DataLink.AsamLinqDataContext())
{
var EName = (from Estate_Info in Dc.Estate_Infos
where Estate_Info.Code == txtEstateCode.Text
select new { EI = Estate_Info.EstateName}) // txtEstateName.DataBindings.Clear();
//txtEstateName.DataBindings.Add("Text", EName, "EI");
return EName;
}


}
but it doesnt work.
Chamika Sandamal 27-Mar-13 4:41am    
Try adding .FirstOrDefault(),
var EName = (from Estate_Info in Dc.Estate_Infos
where Estate_Info.Code == txtEstateCode.Text
select new { EI = Estate_Info.EstateName}).FirstOrDefault();
Hodamdi 28-Mar-13 0:33am    
tanx for your help ,
my problem solved .
Chamika Sandamal 28-Mar-13 1:34am    
then mark it as answer
Member 14174211 2-Apr-19 6:15am    
I want to display filtered records searched via textbox and display result from database in a gridview using linQ

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