Tag: sql

必须使用dbcontext.Database.SqlQuery声明标量变量’@custid’?

我试图使用EF5从bcontext.Database.SqlQuery执行存储过程。 抛出一个错误must declare the scalar variable ‘@custid’ var results = _MiscContext.Database.SqlQuery( “exec sp_GetStaff @custid”, customerNumber).ToList(); 如果customerNumber是工作人员,则SP返回1 ,否则返回empty行。 ALTER PROCEDURE [dbo].[sp_GetStaff] @custid varchar(12) AS BEGIN SET NOCOUNT ON; SELECT 1 AS [C1] FROM [dbo].[Staff] with (nolock) WHERE [CUSTOMER_ID] = @custid END 如何管理?

uniqueidentifier C#中的等效数据类型

什么是uniqueidentifier(Sql server 2005)在C#3.5数据类型中的等价物?

如何在不首先将整个列表加载到内存中的情况下使用Linq to Sql实现SkipWhile?

我需要通过降序发布日期来订购存储在数据库中的文章,然后在Id == 100的文章之后获取前20条记录。 这就是我想对Linq做的事情: IQueryable articles = db.Articles .OrderByDescending(a => a.PublicationDate) .SkipWhile(a => a.Id != 100) .Take(20); 但是,这会生成NotSupportedException,因为Linq to Sql不支持SkipWhile (请参阅此处 )。 一种可能的解决方案是执行查询,然后使用Linq将SkipWhile应用于Object: IEnumerable articles = db.Articles .OrderByDescending(a => a.PublicationDate) .ToList() .SkipWhile(a => a.Article.Id != 100) .Take(20); 但这意味着我需要首先将整个有序列表加载到内存中,然后在Id == 100之后再加载20篇文章。 有没有办法避免这种巨大的内存消耗? 更一般地说,在SQL中实现这一目标的最佳方法是什么?

ExecuteNonQuery()返回受影响的C#的意外行数

这是我的代码 // SqlCommand query = new SqlCommand(“INSERT INTO devis (idProposition, identreprise, tauxHoraire, fraisGenerauxMO, fraisGenerauxPiece, beneficeEtAleas, idStatut, prixUnitaireVenteMO ) VALUES(@idproposition, @identreprise, @tauxHoraire, @fraisGenerauxMO, @fraisGenerauxPiece, @beneficeEtAleas, 1, @prixUnitaireVenteMO) “, Tools.GetConnection()); SqlCommand query = new SqlCommand(“INSERT INTO devis (idProposition, identreprise, tauxHoraire, fraisGenerauxMO, fraisGenerauxPiece, beneficeEtAleas, idStatut, prixUnitaireVenteMO, alerteEntrepriseEnvoyee,fraisDeplacement ) VALUES(1051, 85, 20, 2, 2, 2.2, 1, 88,0,-1) “, Tools.GetConnection()); […]

如何使用ROW_NUMBER对gridview和SQL自定义查询进行分页

我有一个页面执行自定义查询,它保存在数据库的某个地方。 我需要能够在gridview上启用分页。 例如,查询保存在数据库中,如下所示: select * from requestbases 这将返回10,000行。 使用下面的方法,我返回10行。 public DataTable GetGenericResults(string strsql, int pageIndex) { StringBuilder sb = new StringBuilder(); sb.Append(“WITH MyPagedData as ( “); int indexFrom = strsql.IndexOf(“from”); sb.Append(strsql.Substring(0, indexFrom)); sb.Append(“, “); sb.Append(“ROW_NUMBER() OVER(ORDER BY RequestBaseId DESC) as RowNum “); sb.Append(strsql.Substring(indexFrom)); sb.Append(“) “); sb.Append(“SELECT * from MyPagedData where RowNum between @StartIndex and @StartIndex […]

C# – ExecuteNonQuery()不能与SQL Server CE一起使用

我得到了一些应该添加到数据库文件(.sdf)的用户输入的数据。 我选择了Sql Server CE,因为这个应用程序非常小,我没有看到需要使用基于服务的数据库。 好吧,无论如何。 这里是代码: public class SqlActions { string conStr = String.Format(“Data Source = ” + new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + “\\basedados.sdf”); public SqlCeConnection SQLCEConnect() { SqlCeConnection Connection = new SqlCeConnection(conStr); Connection.Open(); return Connection; } public Boolean AdicionarAuditorio(string Nome, int Capacidade) { string Query = “INSERT INTO auditorios (nome, capacidade) VALUES (@Nome, @Capacidade)”; using (var […]

不使用Log()查找位位置

我有一个整数输入,功率为2(1,2,4,8等)。 我希望函数在不使用log()的情况下返回位位置。 例如,对于上面的输入,将分别返回{0,1,2,3}对于C#。 另外,如果这可以在SQL中完成。 谢谢!

validation年龄不低于18岁

如果此人未满18岁,如何显示错误消息? 我使用以下代码,但它始终显示年龄无效,即使我输入的日期早于1995年。 DateTime dt = DateTime.Parse(dob_main.Text); DateTime dt_now = DateTime.Now; DateTime dt_18 = dt.AddYears(-18); if (dt.Date >= dt_18.Date) { MessageBox.Show(“Invalid Birth Day”); }

从数据库中检索图像并在没有httphandler的情况下显示在ASP.NET上

我有一个ASP.NET网站,我想输入EmployeeName,上传EmployeePhoto,然后检索员工信息并在网站上显示Employeephoto。 我用EmployeePhoto创建了一个SQL表 – 输入“image”。 我使用此代码插入照片(工作正常) http://sofzh.miximages.com/c%23/qmphk.png 但是,当我想将我在SQL中插入的照片加载到网站时,我得到的这个Inputstream不存在错误。 加载照片代码和错误http://sofzh.miximages.com/c%23/X2okW.png 我不想使用httphandler解决方案 编辑:我还没有正确答案:( 非常感谢你。 cnn.Open(); SqlCommand cmd = new SqlCommand(“SELECT EmployeeFirstName,EmployeeLastName,EmployeePhoto FROM Employees WHERE EmployeeID = @myvalue”, cnn); cmd.Parameters.AddWithValue(“@myvalue”, (ListBox1.SelectedValue)); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { TextBox1.Text = dr.GetString(0); TextBox2.Text = dr.GetString(1); byte[] imagedata = (byte[])dr[2]; InputStream.Read(imagedata, 0, (byte[])dr[2]); Image Image1 = Image.FromStream(imagedata); } […]

GridView中的ASP.Net显示图像跨越列和行? 使用C#

我有一些想要在Gridview中显示的缩略图。 我不熟悉所提供的所有定制。 基本上我想将图像存储在Gridview中,可能跨越5列宽……然后需要很多行才能完成剩下的工作。 我不想要任何列或行标题,并且真的不希望看到实际网格的证据。 我也想让图像可以点击。 我将从Asp.net中的Sql数据库中提取图像。 我不想将网格绑定到sqldatasource,而是将图像粘贴在网格中,在页面后面的代码中使用某种循环。 这让我感到困惑。 我知道你可以创建一个数据表并添加列和行。 但是,似乎行/列不会跨越。 你将如何存储图像,使其像网格一样工作。 我在下面提供了一些(非常)sudo代码,让你知道我想要做什么。 sudo代码: colcount = 0; rowcount = 0; imagecount = 0; while(images.length > imagecount){ if(colcount < 5){ grid[rowcount][colcount] = images[imagecount]; colcount++; imagecount++; } else{ rowcount++; colcount = 0; } }