I may be going about this the hard way but I am wanting to gather 1 row from the SQL Server database (by ID
column), and place those values inside an instance of my class
(which is chromeExtData
).
My class:
public class chromeExtData
{
public string lname { get; set; }
public string fname { get; set; }
public string mname { get; set; }
public string numsr { get; set; }
public string sor { get; set; }
public string pob { get; set; }
public string birthday { get; set; }
public string cstatus { get; set; }
public string miscnumbers { get; set; }
public List<string> transp { get; set; }
}
And my database layout:
---+-------+-------+-------+-------+-----+-----+----------+---------+-------------+--------
ID | lname | fname | mname | numsr | sor | pob | birthday | cstatus | miscnumbers | transp
---+-------+-------+-------+-------+-----+-----+----------+---------+-------------+--------
5 | Barker| Bob | null | aB342 | U76 | CA | 5/25/1970| Active | A123 | A,X,Y
And what I want to do is just pull that information into the object and vice-versa.
I found this code that I think does what I am wanting to do:
int ID = 5;
using (var dc = new DataContext())
{
var people = dc.ExecuteQuery<chromeExtData>(@"SELECT *
FROM [People]
WHERE [ID] = {0}", ID).ToList();
}
I'm not sure if the code above would place the found data values into the chromeExtData
object or not? I've never used this DataContext
before so I'm unsure if that's the correct way to go about what I want to do.