create proc usp_TblClass_selectAll
as
begin
select * from TblClass
end
winform代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.sqlClient;
namespace _11._12
{
public partial class Form1 : Form
{
string constr = ConfigurationManager.ConnectionStrings["ClassconStr"].ConnectionString;
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender,DataGridViewCellEventArgs e)
{
}
private void Form1_Load(object sender,EventArgs e)
{
List<ClassModel2> list = new List<ClassModel2>();
using (sqlConnection con = new sqlConnection(constr))
{
con.open();
string sp_name = "usp_TblClass_selectAll";
using(sqlCommand cmd=new sqlCommand (sp_name,con))
{
cmd.CommandType = CommandType.StoredProcedure;
using(sqlDataReader reader=cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
ClassModel2 model = new ClassModel2();
model.clsName=reader.Isdbnull(reader.Getordinal("cName"))?string.Empty:reader.GetString(reader.Getordinal("cName"));
model.clsDesc = reader.Isdbnull(reader.Getordinal("cDescription")) ? string.Empty : reader.GetString(reader.Getordinal("cDescription"));
list.Add(model);
}
}
}
}
dataGridView1.DataSource = list;
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。