数据库代码
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;
}
}
}
}
以上是内存溢出为你收集整理的SQLserver--用存储过程在winform的dataGridView空间中显示数据库表全部内容,希望文章能够帮你解决SQLserver--用存储过程在winform的dataGridView空间中显示数据库表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)