Hey guys,

I have a homework assignment to which this form connects to a database via a gridview and the windows form at the bottom has a place at the bottom to enter a last name to which it should do a LINQ to SQL query based on the last name in the database which is activated by the select button. There is one for Minimum and Maximum batting averages. My teacher basically gave us the assignment which very little is talked about in our book. All I know is that the click events for the select buttons activate the query based on the above criteria. Beyond that I don't know where to start. She gave us this on Friday and is due tomorrow morning. I need help and fast! Thanks in advance attached is the zip project file. Oh, I am using Visual Studio 2008 and is in C#, of course.

Recommended Answers

All 2 Replies

try this code:

this will go on Form1_Load

dataBaseBallDataContext db = new dataBaseBallDataContext();

            var Players = from p in db.Players
                          select p;
            List<Player> lstPlayers = Players.ToList();
            playersDataGridView.DataSource = lstPlayers;
            db.Dispose()

this is for seach by last name:

dataBaseBallDataContext db = new dataBaseBallDataContext();
var SearchPlayers = from p in db.Players
                               where (p.LastName.ToUpper() == txtLastName.Text.ToUpper())
                               select p;
List<Player> SearchByLastName = SearchPlayers.ToList();
playersDataGridView.DataSource = SearchByLastName;
db.Dispose();

this is for search by batting average

dataBaseBallDataContext db = new dataBaseBallDataContext();

var SearchPlayersByBatting = from p in db.Players
                               where( p.BattingAverage >= decimal.Parse(txtMin.Text) && p.BattingAverage <= decimal.Parse(txtMax.Text))
                               select p;
List<Player> SearchByBatting = SearchPlayersByBatting.ToList();
playersDataGridView.DataSource = SearchByBatting;
db.Dispose();

Cheers,
Ionut

commented: Great help! +2
commented: Don't give away homework code -1

Thanks it worked!

try this code:

this will go on Form1_Load

dataBaseBallDataContext db = new dataBaseBallDataContext();

            var Players = from p in db.Players
                          select p;
            List<Player> lstPlayers = Players.ToList();
            playersDataGridView.DataSource = lstPlayers;
            db.Dispose()

this is for seach by last name:

dataBaseBallDataContext db = new dataBaseBallDataContext();
var SearchPlayers = from p in db.Players
                               where (p.LastName.ToUpper() == txtLastName.Text.ToUpper())
                               select p;
List<Player> SearchByLastName = SearchPlayers.ToList();
playersDataGridView.DataSource = SearchByLastName;
db.Dispose();

this is for search by batting average

dataBaseBallDataContext db = new dataBaseBallDataContext();

var SearchPlayersByBatting = from p in db.Players
                               where( p.BattingAverage >= decimal.Parse(txtMin.Text) && p.BattingAverage <= decimal.Parse(txtMax.Text))
                               select p;
List<Player> SearchByBatting = SearchPlayersByBatting.ToList();
playersDataGridView.DataSource = SearchByBatting;
db.Dispose();

Cheers,
Ionut

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.