This may be a stupid question but i want to ask anyways :) plus if all works well, i am going to turn this into a tutorial for all to show how easy it is to use LINQ to SQL compared to my other example which i will also post using ADO.Net by using dataadaptors to datasets. But anyways on with the question,
i made a simple database called users, and a windows form with textboxes (which first will come later) but now i go to add a LINQ to SQL class which then i name it MYUserS.dbml, then i add in a class with the name called db, as shown below in the code, my main question is, did i successfully utilize or do LINQ to SQL successfully, if not, can you please tell me how to really do it, so far it seems to pull all the information to the listview successfully, i guess the next step for me is to have the information show up in the textboxes, then have a button to navigate through the database from the starting row to ending, then delete, insert, update etc. anyone know how to do that? most importantly though, did i do LINQ TO SQL successfully?
Thanks
attached is my code and SQL database
Thanks again
code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LINQSQLExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MyUsersDataContext db = new MyUsersDataContext();
public void stringquery()
{
var queryResults = from c in db.tblUsers
select new { FirstN = c.First_Name, LastN = c.Last_Name, JobT = c.Job_Title };
foreach (var peeps in queryResults)
{
ListViewItem lv = new ListViewItem();
lv.Text = peeps.FirstN;
lv.SubItems.Add(peeps.LastN);
lv.SubItems.Add(peeps.JobT);
listView1.Items.Add(lv);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_Submit_Click(object sender, EventArgs e)
{
stringquery();
}
private void btn_Close_Click(object sender, EventArgs e)
{
this.Close();
}
}
}


Sign In
Create Account



Back to top










