连接到数据库后,我可以获取在我的所有列中返回的列的名称SqlDataReader吗?
我经常看到它提到Thread.Sleep();不应该使用,但我不明白为什么会这样.如果Thread.Sleep();可能造成麻烦,是否有任何替代解决方案具有相同的安全性?
例如.
while(true)
{
doSomework();
i++;
Thread.Sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)
另一个是:
while (true)
{
string[] images = Directory.GetFiles(@"C:\Dir", "*.png");
foreach (string image in images)
{
this.Invoke(() => this.Enabled = true);
pictureBox1.Image = new Bitmap(image);
Thread.Sleep(1000);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个C#应用程序,它使用SMTP通过Exchange 2007服务器通过电子邮件发送Excel电子表格报告.这些适用于Outlook用户,但对于Thunderbird和Blackberry用户,附件已重命名为"第1.2部分".
我发现这篇文章描述了这个问题,但似乎没有给我一个解决方法.我无法控制Exchange服务器,因此无法在那里进行更改.我能在C#端做什么吗?我尝试过对身体使用短文件名和HTML编码,但两者都没有区别.
我的邮件发送代码就是这样:
public static void SendMail(string recipient, string subject, string body, string attachmentFilename)
{
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential(MailConst.Username, MailConst.Password);
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(MailConst.Username);
// setup up the host, increase the timeout to 5 minutes
smtpClient.Host = MailConst.SmtpServer;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
smtpClient.Timeout = (60 * 5 * 1000);
message.From = fromAddress;
message.Subject = subject;
message.IsBodyHtml = false;
message.Body = body;
message.To.Add(recipient);
if …Run Code Online (Sandbox Code Playgroud) 我有实体框架生成的以下类:
public partial class ItemRequest
{
public int RequestId { get; set; }
//...
Run Code Online (Sandbox Code Playgroud)
我想把它变成一个必填字段
[Required]
public int RequestId { get;set; }
Run Code Online (Sandbox Code Playgroud)
但是,因为这是生成的代码,这将被消灭.我无法想象一种创建分部类的方法,因为属性是由生成的分部类定义的.如何以安全的方式定义约束?
我有一个来自同事的代码(可能是从网上某处获得的),但是他出去度假,我需要将它添加到清单文件中
<?xml version="1.0" encoding="utf-8" ?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator"
uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>
Run Code Online (Sandbox Code Playgroud)
我对此比较陌生,所以任何帮助都会受到赞赏.谢谢
我正在使用Visual Studio 2010
我正在使用Resharper 4.5,我在编写数组或对象初始化程序时需要自定义大括号格式.Resharper支持一些样式:
Gnu风格:
int[] array = new int[]
{
1, 2, 3
}
Run Code Online (Sandbox Code Playgroud)
但是我需要:
int[] array = new int[]
{
1, 2, 3
}
Run Code Online (Sandbox Code Playgroud)
有没有办法自定义这个模板?
我有以下代码:
const string Sql =
@"select distinct [name]
from tblCustomers
left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId
where (tblCustomer.Name LIKE '%@SEARCH%' OR tblCustomerInfo.Info LIKE '%@SEARCH%');";
using (var command = new SqlCommand(Sql, Connection))
{
command.Parameters.AddWithValue("@SEARCH", searchString);
...
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,我也试过这个:
const string Sql =
@"select distinct [name]
from tblCustomers
left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId
where (tblCustomer.Name LIKE @SEARCH OR tblCustomerInfo.Info LIKE @SEARCH );";
using (var command = new SqlCommand(Sql, Connection))
{
command.Parameters.AddWithValue("@SEARCH", "'%" + searchString + "%'");
... …Run Code Online (Sandbox Code Playgroud) 使用C#.NET 3.5和WCF,我试图在客户端应用程序中写出一些WCF配置(客户端连接到的服务器的名称).
显而易见的方法是使用ConfigurationManager加载配置部分并写出我需要的数据.
var serviceModelSection = ConfigurationManager.GetSection("system.serviceModel");
Run Code Online (Sandbox Code Playgroud)
似乎总是返回null.
var serviceModelSection = ConfigurationManager.GetSection("appSettings");
Run Code Online (Sandbox Code Playgroud)
完美的工作.
配置部分存在于App.config中,但由于某种原因ConfigurationManager拒绝加载该system.ServiceModel部分.
我想避免手动加载xxx.exe.config文件并使用XPath,但如果我不得不求助于我.看起来有点像黑客.
有什么建议?
我有一点问题,希望有人可以给我一些建议.我正在运行一个SQL命令,但它似乎需要这个命令大约2分钟才能返回数据,因为有很多数据.但是默认连接时间是30秒,如何增加它,并将其应用于此命令?
public static DataTable runtotals(string AssetNumberV, string AssetNumber1V)
{
DataTable dtGetruntotals;
try
{
dtGetruntotals = new DataTable("Getruntotals");
//SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 6);
//AssetNumber.Value = AssetNumberV;
SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 10);
AssetNumber.Value = AssetNumberV;
SqlParameter AssetNumber1 = new SqlParameter("@AssetNumber1", SqlDbType.VarChar, 10);
AssetNumber1.Value = AssetNumber1V;
SqlCommand scGetruntotals = new SqlCommand("EXEC spRunTotals @AssetNumber,@AssetNumber1 ", DataAccess.AssetConnection);
// scGetruntotals.Parameters.Add(AssetNumber);
scGetruntotals.Parameters.Add(AssetNumber);
scGetruntotals.Parameters.Add(AssetNumber1);
SqlDataAdapter sdaGetruntotals = new SqlDataAdapter();
sdaGetruntotals.SelectCommand = scGetruntotals;
sdaGetruntotals.Fill(dtGetruntotals);
return dtGetruntotals;
}
catch (Exception ex)
{
MessageBox.Show("Error Retriving totals Details: …Run Code Online (Sandbox Code Playgroud) 我收到了这个错误
msg 8115,level 16,state 2,line 18
将表达式转换为数据类型int的算术溢出错误.
使用此SQL查询
DECLARE @year VARCHAR(4);
DECLARE @month VARCHAR(2);
-- START OF CONFIGURATION SECTION
-- THIS IS THE ONLY SECTION THAT SHOULD BE MODIFIED
-- SET THE YEAR AND MONTH PARAMETERS
SET @year = '2013';
SET @month = '3'; -- 1 = January.... 12 = Decemeber.
-- END OF CONFIGURATION SECTION
DECLARE @startDate DATE
DECLARE @endDate DATE
SET @startDate = @year + '-' + @month + '-01 00:00:00';
SET @endDate = DATEADD(MONTH, 1, @startDate);
SELECT …Run Code Online (Sandbox Code Playgroud) c# ×9
ado.net ×3
.net ×2
sql ×2
sql-server ×2
t-sql ×2
attachment ×1
auto-indent ×1
email ×1
indentation ×1
manifest ×1
resharper ×1
sleep ×1
smtp ×1
sql-like ×1
wcf ×1
xml ×1