Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am developing simple WPF application in that i am using 'grid' tool to bind data from sql but data is not binding to gird (visual studio 2008) here is my code
C#
 SqlConnection con = new SqlConnection(Global.path);
            con.Open();
            string sql = string.Format("select DepartmentCode,DepartmentName from MasterDepartment order by DepartmentCode asc");
            SqlDataAdapter ad = new SqlDataAdapter(sql, con);
            DataTable ds = new DataTable();
            ad.Fill(ds);
grid1.DataContext = ds;
            con.Close();
Posted
Updated 25-Sep-13 12:01pm
v3
Comments
Alexander Dymshyts 24-Sep-13 6:54am    
Create in your class properties DepartmentCode,DepartmentName, and get their values from database. Than you will be able to bind them.
Nikita!8 24-Sep-13 7:02am    
Try writing ItemsSource="{Binding Path=ds, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
in your xmal file instead of grid1.DataContext = ds;

1 solution

try
C#
grid1.DataSource = ds;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900