2

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.

StealthRT
  • 10,108
  • 40
  • 183
  • 342
  • When in doubt you need to check the first-party documentation. Here is the documentation for ExecuteQuery, https://learn.microsoft.com/en-us/dotnet/api/system.data.linq.datacontext.executequery?view=netframework-4.8#System_Data_Linq_DataContext_ExecuteQuery__1_System_String_System_Object___ – Marie May 30 '19 at 14:05
  • 1
    Additionally, did you TRY the code you posted? Just put it in and click F5. see what happens. If you have to add some breakpoints or Console.WriteLines or Debugger writes – Marie May 30 '19 at 14:06

0 Answers0