如何在 C# 中测试性能?
我现在所知道的就是使用:
Stopwatch sw = new Stopwatch();
sw.Start();
{
//code to test
}
sw.Stop();
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以做到这一点还是上述方法错误?
我使用EntityFramework 4,LINQ和C#.
我需要使用Linq从查询表达式在GridView中显示数据; 我需要项目作为anonymous type飞行值计算DateTime.UtcNow - cl.DateLocked注意:cl.DateLocked属于类型DateTime,我需要知道这两个日期之间的差异天数.
使用此查询,我收到一个错误:
DbArithmeticExpression arguments must have a numeric common type.
Run Code Online (Sandbox Code Playgroud)
知道如何在Linq中做到这一点?如果Linq不允许它以不同的方式做到这一点?
谢谢你的时间
var queryContentsLocked = from cl in context.CmsContentsLockedBies
join cnt in context.CmsContents
on cl.ContentId equals cnt.ContentId
join u in context.aspnet_Users
on cl.UserId equals u.UserId
select new
{
cl.DateLocked,
cnt.ContentId,
cnt.Title,
u.UserName,
u.UserId,
TimePan = DateTime.UtcNow - cl.DateLocked // Problem here!!!
};
Run Code Online (Sandbox Code Playgroud) 我已经尝试了每个组合来发送请求从jQuery向RESTful WCF发送POST请求.
有人可以模仿并使其发挥作用.代码在这里:http://pastebin.com/Ua97919C
我在过去2年与WCF合作,但每次发送POST请求都会让我很烦恼.
我努力让它在过去的4天里工作,并且经历了至少35-40个帖子.
最终,此请求将从iPhone发送到WCF.
当我用Fiddler检查时,错误主要是:*服务器遇到处理请求的错误.异常消息是'传入消息具有意外的消息格式'Raw'.操作的预期消息格式是'Xml','Json'.这可能是因为尚未在绑定上配置WebContentTypeMapper.有关更多详细信息,请参阅WebContentTypeMapper的文档.请参阅服务器日志以获取更多详 异常堆栈跟踪是:at
System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
Run Code Online (Sandbox Code Playgroud) 如何将我的数据从SQL Server 2008导出到Excel 2010或更高版本?
我试过SQL方式:
sp_configure 'show advanced options', 0;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 0;
GO
RECONFIGURE;
GO
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\testing.xls;Extended Properties=EXCEL 12.0;HDR=YES',
'SELECT NO_ORDRE, Date FROM [Sheet1$]')
SELECT [NO_ORDRE], GETDATE() FROM ORDRE
GO
Run Code Online (Sandbox Code Playgroud)
不幸的是我收到错误:OLE DB提供程序'Microsoft.Jet.OLEDB.4.0'不能用于分布式查询,因为提供程序配置为在STA模式下运行.
然后我尝试了C#方式:
public class ExportToExcel
{
private Excel.Application app;
private Excel.Workbook workbook;
private Excel.Worksheet previousWorksheet;
// private Excel.Range workSheet_range;
private string folder;
public ExportToExcel(string folder)
{
this.folder = folder;
this.app = null;
this.workbook = null;
this.previousWorksheet = null;
// …Run Code Online (Sandbox Code Playgroud) 我有一个datagrid/gridview.我最初用10行填充网格.每按一次按钮,我就会继续向datagrid/gridview添加10行.现在我想在每次填充网格时将焦点设置到最后一行.我可以获得该行的索引,但我无法将焦点设置为该特定行.
你们其中任何人都知道如何在C#中做到这一点吗?
我的aspx页面中有以下图像
<td>
<asp:Image ID="LargeImage" runat="server" Height="100" Width="100" />"
</td>
Run Code Online (Sandbox Code Playgroud)
在我的aspx.cs中,为此图像指定了一个图像
protected void uploadimage_Click(object sender, System.EventArgs e)
{
ImageUtils.uploadImage(Titletxt.Text, FileUpload.FileContent);
LargeImage.ImageUrl = "~/AvatarImageFetch.ashx?memberid=" + memberid.ToString();
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,图像不会显示.这是我的ashx
public void ProcessRequest(HttpContext context)
{
SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["FMMImages"].ConnectionString);
myConnection.Open();
string sql = "select largeimage from images_temp where id=@memberid";
SqlCommand cmd = new SqlCommand(sql, myConnection);
int param;
int.TryParse(context.Request.QueryString["memberid"], out param);
cmd.Parameters.Add("@memberid", SqlDbType.Int).Value = param;
//cmd.Parameters.Add("@GuID", SqlDbType.UniqueIdentifier).Value = context.Request.QueryString["UID"].ToString();
cmd.CommandType = System.Data.CommandType.Text;
SqlDataReader dReader = cmd.ExecuteReader();
dReader.Read();
context.Response.BinaryWrite((byte[])dReader["largeimage"]);
dReader.Close();
myConnection.Close();
}
Run Code Online (Sandbox Code Playgroud)
另外,我在ashx处理程序中有一个断点.看起来处理程序没有触发.
我有一个excel工作簿,有很多很多页.我想删除除了其中三个之外的所有工作表.
具体来说,我想知道是否有办法使用工作表名称而不是序数(工作表编号)删除工作表.
我正在使用excel interop和C#来使用Excel.
Microsoft.Office.Interop.Excel.Application xlApp = null;
Excel.Workbook xlWorkbook = null;
Excel.Sheets xlSheets = null;
Excel.Worksheet xlNewSheet = null;
Run Code Online (Sandbox Code Playgroud) 我必须完全禁用 Windows 窗体和其中包含的每个控件上的鼠标滚轮,我已经尝试使用事件鼠标滚轮,但它无法正常工作:
this.MouseWheel += new MouseEventHandler(Form_MouseWheel);
private void Form_MouseWheel(object sender, MouseEventArgs e) {
((HandledMouseEventArgs)e).Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
如何在 Windows 窗体及其内部的每个控件中完全禁用鼠标滚轮?
"活动"是一个有点领域.如果其中一个具有此client_id的行的值为true,则需要将其设置为true
SELECT c.client_id, u.branch_id, a.account_id, activity
FROM Clients c INNER JOIN
accounts a ON c.id=a.client_id INNER JOIN uso u ON a.uso_id = u.uso_id,
(SELECT MAX(CONVERT(int,accounts.activity)) as activity, client_id
FROM accounts GROUP BY client_id) activ
WHERE activ.client_id = c.id
Run Code Online (Sandbox Code Playgroud)
此查询执行大约2分钟.请帮我优化一下.
我已经从表中的sql跟踪插入数据,我在解释表中的数据时遇到问题.
在附加的图像中,与我的SP相关的读取非常低,但在下一行中,Text Data列中的值为NULL,读取非常高.
我怎么解释这个.为什么NULL行具有如此高的读取值?
编辑:我已更新图像文件.现在它具有我的跟踪的前10行的所有列名称,我找不到任何EventType列,但是有一个EventClass列,其值为:每行为15行.
