using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Business;

Guys, I want to populate the DataGridview with a dataset I have created but I am having problem and I would be thankful if you help me what went wrong. This is the message I am getting "Error 1 The type or namespace name 'Student' could not be found (are you missing a using directive or an assembly reference?"
Thanks.

namespace School
{
    /// <summary>
    /// Interaction logic for ViewStudents.xaml
    /// </summary>
    public partial class ViewStudents : Window
    {
        public ViewStudents()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SchoolData dt = new SchoolData();
            List<Student> students = (from s in dt.Student
                                      select s).ToList();
 StudentGrid.ItemsSource = students;

Recommended Answers

All 8 Replies

Do you have Student defined? Is it in the namespace School?

Cale
Thanks for the prompt response. In my xaml DataGrid everything is in place including Binding

<DataGrid AutoGenerateColumns="False" Height="211" HorizontalAlignment="Left" Margin="38,12,0,0" Name="StudentGrid" VerticalAlignment="Top" Width="383" Background="White" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="Student ID" Binding="{Binding Path=StudentID}"/>
                <DataGridTextColumn Header="First Name" Binding="{Binding Path=FirstName}"/>
                <DataGridTextColumn Header="Last Name" Binding="{Binding Path=LastName}"/>
                <DataGridTextColumn Header="Gender" Binding="{Binding Path=Gender}"/>
            </DataGrid.Columns>
        </DataGrid>

Can you upload your project file and I will take a look at it.

Thanks, I appreciate your help.

Ok from your initial post I would change List<Student> students to var students. The error you are getting is because VS is expecting a "Student" class. Although your xsd file contains the Student table, it does not contain a Student class (a downside to using xsd files).

Ok from your initial post I would change List<Student> students to var students. The error you are getting is because VS is expecting a "Student" class. Although your xsd file contains the Student table, it does not contain a Student class (a downside to using xsd files).

Thanks but I still have that error!!

string connectionString = "server=localhost;database=nidhiprac;uid…
SqlConnection mySqlConnection = new SqlConnection(connectionString);
string selectString = "SELECT * FROM authors";
SqlCommand mySqlcommand = mySqlConnection.CreateCommand();
mySqlcommand.CommandText = selectString;
SqlDataAdapter mySqldataAdapter = new SqlDataAdapter();
mySqldataAdapter.SelectCommand = mySqlcommand;
System.Data.DataSet ds = new System.Data.DataSet();

this code apply in Sql Server in C sharp........
Source(s):
string connString = @"server=localhost;Database=Nidhiprac;Us… ID=root;Password=supra;";
MySqlConnection conn = new MySqlConnection(connString);
try
{
conn.Open();
Console.WriteLine("Connection Opened");
Console.WriteLine("Connection Properties:");
Console.WriteLine("\tConnection String: {0}", conn.ConnectionString);
Console.WriteLine("\tDatabase: {0}", conn.Database);
Console.WriteLine("\tServerVersion: {0}",conn.ServerVersion);
Console.WriteLine("\tState: {0}",conn.State);
}
catch (MySqlException e)
{
Console.WriteLine("Error: " + e);
}
finally
{
conn.Close();
Console.WriteLine("Connection closed.");
}

this connectio is in My Sql.......... in C sharp

shiva07
Thanks but that's not what I need it. did you check my code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.