WPF DataGrid 绑定到List集合
2021-01-04 07:27
标签:访问 tst ssid can sel str int ssi cli 最近尝试用WPF重新编写之前用WinForm编写的应用程序,在使用中,需要从数据库查询到一系列数据库,在前台DataGrid里面显示出来。 using System; namespace StudentDAL } 学员实体类: namespace StudentsModules } using System; namespace StudentsModules 后台设置数据源: WPF DataGrid 绑定到List集合 标签:访问 tst ssid can sel str int ssi cli 原文地址:https://www.cnblogs.com/Use-NPOI/p/13196323.html
后台 :
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using StudentsModules;
using ELP;
{
public class StudentServices
{
private ErrorLogProcessing errorLogp = new ErrorLogProcessing();
private SqlHelper helper = new SqlHelper(); public void StudentAdd(Students students)
{
try
{
string str = "insert into Students(StudentName,Gender,Birthday,StudentIdNo,CarNo,StuImage,Age,PhoneNumber,studentAddress,ClassId)" +
" values (‘{0}‘,‘{1}‘,{2},‘{3}‘,‘{4}‘,‘{5}‘,{6},‘{7}‘,‘{8}‘,{9})";
str = string.Format(str, students.StudentName, students.Gender, students.Birthday, students.StudentIdNo, students.CarNo, students.StuImage, students.Age,
students.PhoneNumber, students.StudentAddress, students.ClassId);
int a= helper.UpdateData(str);
上面有直接拼接SQL语句的,使用参数化的SQL最好还是使用SqlParameter封装参数,然后传递给数据库访问方法
}
catch(Exception ex)
{
errorLogp.WriteErrorLog(ex);
}
}
public List
using System;
using System.Collections.Generic;
using System.Text;
{
///
/// 学员实体类
///
public class Students
{
///
/// 学员编号
///
public int StudentId { get; set; } ///
学员实体扩展类:
using System.Collections.Generic;
using System.Text;
{
public class StudentExt:Students
{
public string ClassName { get; set; }
}
}
前台XAML:
private void BtnLoaddata_Click(object sender, RoutedEventArgs e)
{ this.DGview.ItemsSource = GetStudentServices.GetAllStudent();
}
上一篇:C# 关键字:new
下一篇:MS-API。AJAS
文章标题:WPF DataGrid 绑定到List集合
文章链接:http://soscw.com/index.php/essay/39991.html