string strConnection = "Data Source=.;Initial Catalog=CustomerDB1;Persist Security Info=True;User ID=sa;Pooling=False";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
string strCommand = "Select * From Customer";
SqlCommand objCommad = new SqlCommand(strCommand, objConnection);
DataSet objDataSet = new DataSet();
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommad);
dtgCustomer.DataSource = objDataSet.Tables[0];
objConnection.Close();
错误
尝试了多种方法,
你的连接串里连password都没有,是怎么登录的呢
首先,因为我测试的SQL为select * from wyj..tb_person;
,所以要确保数据库里有对应的库、表、几行测试数据。脚本:
create database wyj;
use wyj;
go
create table tb_person (
id int,
name nvarchar(20)
);
insert into wyj..tb_person (id, name) values
(1, 'one'),
(2, 'two'),
(3, 'three'),
(4, 'four');
select * from wyj..tb_person;
Debug
鼠标移动至DataSet
类型的变量resultTable
上方,点击悬浮窗中的小放大镜,可以看到DataSet 可视化工具
。
或由代码便利返回的对象:
除了你的strconnect没有看到密码,再检查一下sa的状态setting是否允许了连接