C#调用sql存储过程的简单的例子 然后把得到的表赋值给datagridview1
createprocbrowsasselectname,departmentemployeeinnerjoincomputeronemployee.id=computer...
create proc brows
as
select name,department employee inner join computer on employee.id=computer.id
go
exec brows
连接语句
string MyConn = "Data Source=FQ-201105041133;Initial Catalog=sbgl;User ID=sa";
求解,本人新手,最好写详细一点,不要复制粘贴上网址的,谢谢 展开
as
select name,department employee inner join computer on employee.id=computer.id
go
exec brows
连接语句
string MyConn = "Data Source=FQ-201105041133;Initial Catalog=sbgl;User ID=sa";
求解,本人新手,最好写详细一点,不要复制粘贴上网址的,谢谢 展开
1个回答
展开全部
创建一个连接SqlConnection connection = new SqlConnection(MyConn)
创建一个command对象SqlCommand command = connection.CreateCommand()
command.CommandText = 存储过程名,你这里就是brows
command.CommandType = CommandType.StoredProcedure
DataTable dt = new DataTable();
创建一个适配器对象
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dt);
dt里就是查出来的数据,赋值datagridview1.DataSource = dt.DefaultView
创建一个command对象SqlCommand command = connection.CreateCommand()
command.CommandText = 存储过程名,你这里就是brows
command.CommandType = CommandType.StoredProcedure
DataTable dt = new DataTable();
创建一个适配器对象
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dt);
dt里就是查出来的数据,赋值datagridview1.DataSource = dt.DefaultView
追问
抓狂,居然把关键部分给省略了...
追答
哪个关键部分- -!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询