Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据无法获取_C# - Fatal编程技术网

C# 数据无法获取

C# 数据无法获取,c#,C#,在这里,我使用了数据集的数据库连接,但我没有得到数据 你能帮我找出下面代码中的错误吗 string con = @"Data Source=HA-INT13\SQL2008;" + "Initial Catalog=AdventureWorks;Integrated Security=True;database=AdventureWorks;user=sa;password=sa123"; dsReports =

在这里,我使用了数据集的数据库连接,但我没有得到数据

你能帮我找出下面代码中的错误吗

              string con = @"Data Source=HA-INT13\SQL2008;" + "Initial Catalog=AdventureWorks;Integrated Security=True;database=AdventureWorks;user=sa;password=sa123";               
             dsReports = new DataSet();
             daAdapter = new SqlDataAdapter("select * from dbo.Employees",con);
             SqlCommandBuilder cmdbldr = new SqlCommandBuilder(daAdapter);
             daAdapter.Fill(dsReports,"dbo.Employee"); 
谢谢, Rajasekhar

试着去掉“dbo.Employee”参数并继续

dAdapter.Fill(dsReports)

我不知道这是否是答案,但据我所知,你只使用

Integrated Security=true
当您使用windows帐户时。如果希望使用要传递的用户名和密码,则需要删除连接字符串的集成安全部分


我可能完全错了,但我认为这就是问题所在。

因为我看到您添加了错误的sql连接字符串,初始Catlog和数据库显示了两次


是否需要打开数据库连接<代码>daAdapter.SelectCommand.Connection.Open()?另外,您已经指定了两次数据库名称,第一次是
Initial Catalog=
,然后是
database=
str ConnString = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"