草庐IT

sql语句SQLServer

全部标签

c# - Linq-to-sql 错误 : 'int[]' does not contain a definition for 'Contains'

我有一个错误:错误2'int[]'不包含'Contains'的定义并且最佳扩展方法重载'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable,TSource)'有一些无效参数这是我的代码:publicpartialclassmymymy:System.Web.UI.Page{int[]validType={2,3,4,5,6,8,13,14,16,22};protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidLinqDataSou

c# - 我们在哪里使用 Debug/Trace 语句

我使用C#(使用VSIDE)进行开发。我对调试/跟踪语句感到困惑。我们在哪里以及为什么使用这些语句?我经常在其他开发人员的源代码中看到这些。谁能指点一下? 最佳答案 Debug语句仅出现在Debug版本中。Trace语句存在于调试和发布版本中。为了调试或检查,您可以将Debug和Trace语句放在要输出某些值的地方。这篇MS支持文章可能会引起您的兴趣:HowtotraceanddebuginVisualC#TheTraceclassroutesmessagestolisteners:classesthataredesignedtoa

c# - 使用 linq to sql 获取最后一个元素

我有这个:varresult=(fromtinMyDCwheret.UserID==6orderbyt.UpdateTimeselectt.ID).Last();基本上,我使用的是Linq-to-Sql,它不支持.Last运算符。我可以检索用户的所有记录,然后使用linqtoobjects来获取我的值,但我想知道如何使用linq-to-sql执行此操作并仅返回一条记录。感谢您的建议。 最佳答案 只需按降序排列并使用.First()代替:varresult=(fromtinMyDCwheret.UserID==6orderbyt.Up

c# - 从 linq to sql 中的子查询中选择前 1 个结果

下面是我的sql查询selectenq_Id,enq_FromName,enq_EmailId,enq_Phone,enq_Subject,enq_Message,enq_EnquiryBy,enq_Mode,enq_Date,ProductId,(selecttop1image_namefromtblProductImageasiwherei.product_id=p.product_Id)asimageName,p.product_Name,p.product_codefromtblEnquiryaseinnerjointblProductaspONe.ProductId=p.pr

c# - 如何从 C# 执行 .sql?

对于某些集成测试,我想连接到数据库并运行一个.sql文件,该文件具有实际运行测试所需的架构,包括GO语句。如何执行.sql文件?(或者这是完全错误的方法吗?)我找到了apostintheMSDNforum显示此代码:usingSystem.Data.SqlClient;usingSystem.IO;usingMicrosoft.SqlServer.Management.Common;usingMicrosoft.SqlServer.Management.Smo;namespaceConsoleApplication1{classProgram{staticvoidMain(string

c# - 舍入 .NET DateTime 毫秒,因此它可以适合 SQL Server 毫秒

我想将日期时间值转换为将从SQLServer2008获得的值。SQLServer将毫秒截断为3位数,所以我已经截断了毫秒。但问题是,正如您在这里看到的:MillisecondswrongwhenconvertingfromXMLtoSQLServerdatetime.SQLServer也有一个精度问题。 最佳答案 这是你想要的:usingSystem.Data.SqlTypes;//fromSystem.Data.dllpublicstaticDateTimeRoundToSqlDateTime(DateTimedate){retu

c# - T-Sql 中的时间戳在 C# 中意味着什么?

我正在尝试开发一个模型对象来保存SqlServer行,并且我完全理解如何执行此操作,除了T-Sql/SqlServer时间戳。该表定义为:CREATETABLEactivity(activity_idint,ip_addressvarchar(39),user_idvarchar(255),message_text,dttimestamp)当我将一个表行解析为我的对象时,对于一个int或一个字符串,我希望做类似的事情:ActivityID=(int)dataReader["activity_id"];IPAddress=(string)dataReader["ip_address"];

c# - 使用 linq-to-sql 批量插入

我有一个如下所示的查询:using(MyDCTheDC=newMyDC()){foreach(MyObjectTheObjectinTheListOfMyObjects){DBTableTheTable=newDBTable();TheTable.Prop1=TheObject.Prop1;.....TheDC.DBTables.InsertOnSubmit(TheTable);}TheDC.SubmitChanges();}这个查询主要是使用linq-to-sql将一个列表插入到数据库中。现在我在网上看到L2S不支持批量操作。我的查询是通过一次插入每个元素还是在一次写入中插入所有元素

c# - 在 LINQ 查询 'if' 语句中实现条件 'where' 语句

我正在尝试找出一种在我的数据模型中查询对象的方法,并且只包含那些不为空的参数。如下所示:publicListGetWidgets(stringcond1,stringcond2,stringcond3){MyDataContextdb=newMyDataContext();Listwidgets=(fromwindb.Widgetswhere...ifcond1!=nullw.condition1==cond1......ifcond2!=nullw.condition2==cond2......ifcond3!=nullw.condition3==cond3...selectw).T

c# - 在一种方法中使用多个 RETURN 语句是一种好习惯吗?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whyisitgoodpracticetoreturnattheendofamethod我想知道在一个方法中使用多个RETURN语句是否可以被视为良好做法,以及为什么。如果没有,我想知道您将如何以不同的方式重写代码。publicstringGetNominativeById(int?candidateId){if(candidateId.HasValue)returnrepepositoryCandidate.GetById(candidateId.Value).Nominative;elsereturnst