Tag: sql server 2005

C#SqlCommand – 不能使用参数作为列名,如何解决?

有什么方法可以做到吗? 这不起作用: SqlCommand command = new SqlCommand(“SELECT @slot FROM Users WHERE name=@name; “); prikaz.Parameters.AddWithValue(“name”, name); prikaz.Parameters.AddWithValue(“slot”, slot); 我唯一能想到的是使用SP并声明并设置列的变量。 对我来说有点尴尬。

entity framework – 在sql server表中未设置默认值

SQL Server 2005数据库表有一个“createdon”列,其默认值设置为getdate()。 我试图使用entity framework添加记录。 ‘createdon’列未获得更新。 我是否错过了Entity框架中的任何属性,请提出建议。

我该如何多次插入多条记录?

我有一个名为Entry的类,声明如下: class Entry{ string Id {get;set;} string Name {get;set;} } 然后使用ADO.NET接受多个这样的Entry对象插入数据库的方法: static void InsertEntries(IEnumerable entries){ //build a SqlCommand object using(SqlCommand cmd = new SqlCommand()){ … const string refcmdText = “INSERT INTO Entries (id, name) VALUES (@id{0},@name{0});”; int count = 0; string query = string.Empty; //build a large query foreach(var entry in entries){ query += string.Format(refcmdText, […]

SqlDataSourceEnumerator.Instance.GetDataSources()找不到本地SQL Server 2008实例

我使用以下代码列出所有远程和本地SQL Server实例: public static void LocateSqlInstances() { using( DataTable sqlSources = SqlDataSourceEnumerator.Instance.GetDataSources()) { foreach(DataRow source in sqlSources.Rows ) { string instanceName = source[“InstanceName”].ToString(); if (!string.IsNullOrEmpty(instanceName)) { Console.WriteLine(” Server Name:{0}”, source[“ServerName”]); Console.WriteLine(” Instance Name:{0}”, source[“InstanceName”]); Console.WriteLine(” Version:{0}”, source[“Version”]); Console.WriteLine(); } } Console.ReadKey(); } } 在我的本地计算机上运行代码。 代码可以查找并列出已安装但未列出其他SQL Server实例(版本10.0.1600)的SQL Server express实例(版本9.0.5000)。 我已经在互联网上做了很多研究,并确保1-Sql Broswer正在运行,2 – UDP端口1434是开放的。 谁知道为什么? 谢谢。