Adventure work Access to customer information

I am doing a project using the AdventureWorks database and I am trying to access the database so that users can change their credentials. Users for the website are configured using the ASP.NET configuration manager, so I'm not sure how to do this. I have a GetCustomer Select method configured to select (at the moment) only the first and last client names in the Person.Contact table.

[DataObject(true)] public static class CustomerDB { [DataObjectMethod(DataObjectMethodType.Select)] public static List<Customer> GetCustomer() { List<Customer> CustomerList = new List<Customer>(); SqlConnection con = new SqlConnection(GetConnectionString()); string sel = "SELECT Person.Contact.FirstName, Person.Contact.LastName " + "FROM Person.Contact " + "JOIN Sales.Individual ON Person.Contact.ContactID = Sales.Individual.ContactID " + "JOIN Sales.Customer ON Sales.Individual.CustomerID = Sales.Customer.CustomerID " + "WHERE Sales.Customer.CustomerType = Sales.Individual " + "ORDER BY Person.Contact.LastName, Person.Contact.FirstName"; SqlCommand cmd = new SqlCommand(sel, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Customer customer; while (rdr.Read()) { customer = new Customer(); customer.FirstName = rdr["FirstName"].ToString(); customer.LastName = rdr["FirstName"].ToString(); CustomerList.Add(customer); } rdr.Close(); return CustomerList; } private static string GetConnectionString() { return ConfigurationManager.ConnectionStrings ["AdventureWorksString"].ConnectionString; } 

But I get an error: Msgstr "Invalid object name" Person.Contact "." which makes me think this is a problem. The query I'm using is based on one example script on the Msdn website. If someone could point me in the right direction, taking into account which tables to use to obtain information about the client, so that the user can change his address and password, I would be very grateful!

+5
source share
2 answers

This can do the trick for you.

 string sel = "SELECT pc.FirstName, pc.LastName " + "FROM Person.Contact pc " + "JOIN Sales.Individual ON pc.ContactID = Sales.Individual.ContactID " + "JOIN Sales.Customer ON Sales.Individual.CustomerID = Sales.Customer.CustomerID " + "WHERE Sales.Customer.CustomerType = Sales.Individual " + "ORDER BY pc.LastName, pc.FirstName"; 
0
source

Check for the Person.Contact and Sales.Individual in the AdventureWorks database. Since this error, the Invalid object name 'Person.Contact' will occur on tables or is missing from the database.

I just restored a backup of the AdventureWorks database. It does not have a Person.Contact table! Sales.Individual also missing

0
source

Source: https://habr.com/ru/post/1238061/


All Articles