【发布时间】:2011-05-17 07:08:03
【问题描述】:
我有以下 C# 代码:
public string TargetDate()
{
SqlConnection con =
new SqlConnection("Server=localhost;Database=Timer;Trusted_Connectopn=True");
SqlCommand cmd = new SqlCommand("select * from Timer");
con.Open();
DataSet ds = new DataSet(cmd,con);
SqlDataAdapter da = new SqlDataAdapter();
da.Fill(ds);
con.Close();
}
但我收到错误:new DataSet(cmd,con); ...
错误:CS1502:最好重载
的方法匹配'System.Data.DataSet.DataSet(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext)' 有一些无效的参数
可能是什么问题?
【问题讨论】:
-
您好,连接字符串应该是“Server=localhost;Database=Timer;Trusted_Connection=True”。谢谢。
-
你也可以试试MSDN上的文档,Populating a DataSet from a DataAdapter
标签: c# .net asp.net sql sql-server