我们刚刚在一个旧的生产存储过程中遇到过这个问题(这里还有很多内容,但这只是其逻辑的一个部分).为什么有人会从表中选择前0行?这是某种我不熟悉的SQL黑客或技巧吗?
我不知道是否有这个"模式",其中一个方法签名被称为TrySomething,如姓名int.TryParse,decimal.TryParse等等.
我的一个同事经常使用这个命名约定 - 而不是返回值或抛出异常,他们将调用一个方法TryDoSomething,如果在处理期间捕获异常,它将通过out param返回.
编辑:我理解私有的例子不是TryParse方法的工作原理.这就是张贴这个......我不知道该怎么称呼它.我同意它似乎更像是命名约定而不是模式.感谢所有的投入.
编辑:有趣 ......
考虑可能在常见场景中抛出异常的成员的TryParse模式,以避免与异常相关的性能问题.
要实现TryParse模式,您需要提供两种不同的方法来执行可在常见方案中引发异常的操作.第一个方法X执行操作并在适当时抛出异常.第二种方法TryX不会抛出异常,而是返回一个表示成功或失败的布尔值.使用out(Visual Basic中的ByRef)参数返回成功调用TryX返回的任何数据.Parse和TryParse方法就是这种模式的例子.
我在VS中启动了一个新的空白控制台应用程序项目(我正在使用VS2010),并选择"添加服务引用"到受用户名和密码保护的Web服务.
当我在对话框中单击Go时,我遇到了是/否提示接受证书.我选择是,然后我到达Discovery Credential提示,询问用户名和密码.
如果我多次正确地键入那些(3+),我终于获得了对WSDL的访问权限.或者,奇怪的是,如果我正确地键入它们一次,然后取消,然后再次完成该过程,我的信用卡在第一次尝试时被接受.
我问了谷歌,发现了一些与SQL报告网络服务有关的实例,有人在这里发布了类似的东西,但似乎没有人有明确的答案.
谁能解释这种奇怪的行为?服务是否配置不正确,或者这是Web服务或WCF服务的某种已知问题?
给定以下带有单个char(1)列的SQL Server表:
Value
------
'1'
'2'
'3'
Run Code Online (Sandbox Code Playgroud)
如何在T-SQL中获得以下结果?
Result
------
'1+2+3'
'1+3+2'
'2+1+3'
'2+3+1'
'3+2+1'
'3+1+2'
Run Code Online (Sandbox Code Playgroud)
这也需要是动态的,所以如果我的表只保存行'1'和'2',我期望:
Result
------
'1+2'
'2+1'
Run Code Online (Sandbox Code Playgroud)
看起来我应该能够使用CROSS JOIN来做到这一点,但由于我不知道会提前有多少行,所以我不确定CROSS JOIN会多少次回到自己身上......?
SELECT a.Value + '+' + b.Value
FROM MyTable a
CROSS JOIN MyTable b
WHERE a.Value <> b.Value
Run Code Online (Sandbox Code Playgroud)
在任何给定时间总是会有少于10行(实际上更像是1-3行).我可以在SQL Server中即时执行此操作吗?
编辑:理想情况下,我希望这发生在一个存储过程中,但如果我必须使用另一个proc或一些用户定义的函数来解决这个问题,我就可以了.
string Path = @"c:\Database\Mydatabase.db";
string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties=Paradox 5.x;";
// Define the database query
string mySelectQuery = "SELECT id,name FROM people WHERE id < 3;";
// Create a database connection object using the connection string
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
// Create a database command on the connection using query
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
// Open the connection
myCommand.Connection.Open();
// Create a database reader
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
Run Code Online (Sandbox Code Playgroud)
错误发生在myCommand.Connection.Open(); 它说:'c:\ Database\Mydatabase.db'不是有效的路径.确保路径名拼写正确,并且您已连接到文件所在的服务器.
我试图在C#中读取.db文件.但是,我收到一个错误,我确信文件位于那里,错误对我来说没有意义.请你帮助我好吗 …
我目前的代码是:
public static byte[] ImageToByte(Image img)
{
byte[] byteArray = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
stream.Close();
byteArray = stream.ToArray();
}
return byteArray;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个工作与多线程,或使用我的CPU的每个核心,使其更快?
这可能是一个愚蠢的问题,但我想知道我的代码是否在编程上是正确的.
private void Connect()
{
try
{
// I will do something here
}
catch(Exception ex)
{
// If something bad happened
// I want to ignore the problem and continue the execution
// So, nothing will be placed in the catch block
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我想从c#中的winform应用程序直接写一个简单的文本文件到用户的桌面,不被拒绝.我怎样才能得到这条路?提前致谢.
cmd.CommandText = "select name from Tbl_Shahr_No";
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
reader.Read();
while(reader.HasRows)
{
ddl.Items.add(reader["name"].tostring());
reader.read()
}
Run Code Online (Sandbox Code Playgroud)
我写了这段代码,但问题是虽然声明一直都是真的!如何使用while转发器环读取所有读卡器信息?
这是我的代码:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string appdata = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
string subFolderPath = System.IO.Path.Combine(appdata, ".minecraft");
string bin = System.IO.Path.Combine(subFolderPath, "bin");
string mods = System.IO.Path.Combine(subFolderPath, "mods");
string coremods =System.IO.Path.Combine(subFolderPath, "coremods");
string config = System.IO.Path.Combine(subFolderPath, "config");
if (Directory.Exists(mods)) Directory.Delete(mods,true);
if (Directory.Exists(config)) Directory.Delete(config, true);
if (Directory.Exists(coremods)) Directory.Delete(coremods, true);
FastZip fZip1 = new FastZip();
fZip1.ExtractZip(@"C:\Users\Rafa\Desktop\MagicFarm.zip", subFolderPath, "config");
FastZip fZip = new FastZip();
fZip.ExtractZip(@"C:\Users\Rafa\Desktop\MagicFarm.zip", subFolderPath, "mods");
FastZip fZip2 = new FastZip();
fZip2.ExtractZip(@"C:\Users\Rafa\Desktop\MagicFarm.zip", subFolderPath, "coremods");
Run Code Online (Sandbox Code Playgroud)
我想把"C:\ Users\Rafa\Desktop\MagicFarm.zip"放在项目目录中.
有人能帮我吗?
c# ×8
.net ×2
database ×2
sql ×2
sql-server ×2
credentials ×1
discovery ×1
exception ×1
memorystream ×1
paradox ×1
permutation ×1
t-sql ×1
try-catch ×1
wcf ×1
web-services ×1
winforms ×1