Exemplo n.º 1
0
 private void FillGridView()
 {
     GridViewName.DataSource = broker.Fill();
     GridViewName.DataBind();
 }
Exemplo n.º 2
0
        private void DisplayContactDetails(string contactId)
        {
            string contactQueryString = "SELECT ContactId, LastName, FirstName, MiddleInitial FROM Contact WHERE ContactId = @ContactId";
            string addressQueryString = "SELECT AddressId, Street, StreetLineTwo,City,State,ZipCode,PrimaryAddress, ContactId FROM Address " +
                                        "WHERE ContactId = @ContactId AND Country='USA'";
            string eMailQueryString = "SELECT EmailId, UserName,Domain,PrimaryEmail, ContactId FROM Email WHERE ContactId = @ContactId";
            string phoneQueryString = "SELECT PhoneId, Type, AreaCode, PhoneNumberPOne,PhoneNumberPTwo,Extension,PrimaryNumber, ContactId " +
                                      "FROM Phone WHERE ContactId = @ContactId AND CountryCode='1'";
            string internationalPhone = "SELECT PhoneId, Type, CountryCode, PrimaryNumber, ContactId, International FROM Phone " +
                                        "WHERE ContactId=@ContactId AND CountryCode!='1'";

            using (SqlConnection connection = new SqlConnection(connectionString)) {
                connection.Open();
                DataSet dataSet = new DataSet();

                SqlDataAdapter contactAdapter = new SqlDataAdapter();
                contactAdapter.TableMappings.Add("Table", "Contact");
                SqlCommand cCommand = new SqlCommand(contactQueryString, connection);
                cCommand.Parameters.AddWithValue("ContactId", contactId);
                contactAdapter.SelectCommand = cCommand;
                contactAdapter.Fill(dataSet);

                SqlCommand aCommand = new SqlCommand(addressQueryString, connection);
                aCommand.Parameters.AddWithValue("ContactId", contactId);
                SqlDataAdapter addressAdapter = new SqlDataAdapter();
                addressAdapter.TableMappings.Add("Table", "Address");
                addressAdapter.SelectCommand = aCommand;
                addressAdapter.Fill(dataSet);

                SqlCommand eCommand = new SqlCommand(eMailQueryString, connection);
                eCommand.Parameters.AddWithValue("ContactId", contactId);
                SqlDataAdapter eMailAdapter = new SqlDataAdapter();
                eMailAdapter.TableMappings.Add("Table", "Email");
                eMailAdapter.SelectCommand = eCommand;
                eMailAdapter.Fill(dataSet);

                SqlCommand pCommand = new SqlCommand(phoneQueryString, connection);
                pCommand.Parameters.AddWithValue("ContactId", contactId);
                SqlDataAdapter phoneAdapter = new SqlDataAdapter();
                phoneAdapter.TableMappings.Add("Table", "Phone");
                phoneAdapter.SelectCommand = pCommand;
                phoneAdapter.Fill(dataSet);

                SqlCommand iPCommand = new SqlCommand(internationalPhone, connection);
                iPCommand.Parameters.AddWithValue("ContactId", contactId);
                SqlDataAdapter iPAdapter = new SqlDataAdapter();
                iPAdapter.TableMappings.Add("Table", "InternationalPhone");
                iPAdapter.SelectCommand = iPCommand;
                iPAdapter.Fill(dataSet);

                connection.Close();

                GridViewName.DataSource = dataSet.Tables["Contact"];
                GridViewName.DataBind();
                AddressGridView.DataSource = dataSet.Tables["Address"];
                AddressGridView.DataBind();
                EmailGridView.DataSource = dataSet.Tables["Email"];
                EmailGridView.DataBind();
                PhoneGridView.DataSource = dataSet.Tables["Phone"];
                PhoneGridView.DataBind();
                InternationalPhoneGridView.DataSource = dataSet.Tables["InternationalPhone"];
                InternationalPhoneGridView.DataBind();
            }
        }