我正在使用SQL Server 2005.我正在使用ROUND T-SQL函数来舍入十进制列值.但似乎舍入值不正确.
PRINT ROUND(1890.124854, 2) => 1890.120000
Run Code Online (Sandbox Code Playgroud)
如图所示,ROUND函数返回1890.12,因为它应该是1890.13.有没有人遇到过这个以及什么应该是正确的舍入方式,以便我得到预期值1890.13 ..?
谢谢.
我用sql写的:
CREATE SYMMETRIC KEY SecureSymmetricKey
WITH ALGORITHM = TRIPLE_DES
ENCRYPTION BY PASSWORD = 'StrongPassword';
Run Code Online (Sandbox Code Playgroud)
DECLARE @str NVARCHAR(1000)
SET @str = 'lala';
OPEN SYMMETRIC KEY SecureSymmetricKey
DECRYPTION BY PASSWORD = 'StrongPassword';
Run Code Online (Sandbox Code Playgroud)
DECLARE @encrypted_str VARBINARY(MAX)
SET @encrypted_str =
EncryptByKey(Key_GUID('SecureSymmetricKey'), @str);
Run Code Online (Sandbox Code Playgroud)
我怎样才能在c#中阅读它?(并在c#中解密)
我试图将一些数据插入我的数据库(sql server/local文件),但它不起作用.
public bool SaveCookie(string cookie, string expires)
{
SimpleDBM db = new SimpleDBM();
db.Connect();
try
{
string query = string.Format("INSERT INTO Cookies(cookie_value, cookie_expires) VALUES('{0}', '{1}');", cookie, expires);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
//...
SqlDataReader data = db.Query(ref cmd);
return data.Read();
}
catch
{
return false;
}
finally
{
db.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
本SimpleDBM类:
public class SimpleDBM {
public static string dbpath = @"...";
public static string dbname = "db.mdf";
public static string dfullPath = Path.Combine(dbpath, …Run Code Online (Sandbox Code Playgroud) 我想用C#创建一个ASP.Net应用程序,我将在SQL Server 2005上存储数据,这些数据将被加密我想找到一个算法用C#加密数据并在SQL服务端解密它我想要使用SQL加密某些数据并使用C#解密它的最佳算法是什么?
private byte[] key = {
0x61,
0x72,
0x84,
0x7a,
0x24,
0x43,
0x65,
0x64,
0x73,
0x55,
0x64,
0x75,
0x66
};
const string PASSWORD = "TestPassword";
public object Encrypt(string sPlainText)
{
byte[] aPlainBytes = null;
PasswordDeriveBytes aPassword = default(PasswordDeriveBytes);
aPlainBytes = System.Text.Encoding.Unicode.GetBytes(sPlainText);
aPassword = new PasswordDeriveBytes(PASSWORD, key);
byte[] sEncryptedData = Encrypt(aPlainBytes, aPassword.GetBytes(32), aPassword.GetBytes(16));
//' MessageBox.Show(Convert.ToString(sEncryptedData.ToString))
return Convert.ToBase64String(sEncryptedData);
}
private byte[] Encrypt(byte[] sPlainData, byte[] aKey, byte[] aIV)
{
MemoryStream oMemoryStream = new MemoryStream();
Rijndael oRijndael = Rijndael.Create();
oRijndael.Key = aKey; …Run Code Online (Sandbox Code Playgroud) 我在Web窗体上有一个TextBox服务器控件,比如txtDueDate.我不想使用DateTimePicker但想要使用TextBox本身.用户以dd/mm/yyyy格式输入日期.
将此值传递给SQL Server 2005(Express)存储过程时,我使用类似于:
cmdParameters.AddWithValue("@DueDate", Convert.ToDateTime(txtDueDate.Text));
Run Code Online (Sandbox Code Playgroud)
存储过程具有输入参数来处理此值,并声明为:
@DueDate SmallDateTime
Run Code Online (Sandbox Code Playgroud)
我想知道SQL Server 2005在内部用于存储此日期的默认格式.在我的PC上,Windows XP区域设置被设置为dd/mm/yyyy格式.在通过Management Studio查看记录时,它会正确存储.但我担心将使用此Web应用程序的用户.Windows区域设置可能在其PC上有所不同.
我想确定谁查询数据库,日期以dd/mm/yyyy格式显示.如果有人插入,02/01/2004,那么它不应该成为有效的反向日期,如:01/02/2004.
我希望检索myDate在startDate'和endDate' 之间的所有记录,但不返回具有完全相同日期的记录.我正在使用MS SQL 2005.
我试过了:
Select *
From myDatabase
Where empId = 145
and myDate between startDate and endDate
但是如果myDate是'11/16/2011',则上述查询将返回具有startDate和endDate= '11/16/2011'的记录.这不是我想要的.我不想要有startDate和endDate=的记录myDate
所以我尝试过:
Select *
From myDatabase
Where empId = 145
and myDate between startDate and endDate
and (myDate <> startDate AND myDate <> endDate)
这适用于所有情况吗?
我想设计一个看起来像这样的表:
avaya nchar(6) NOT NULL,
startDate datetime NOT NULL,
endDate datetime NOT NULL,
sup_assigned nvarchar(255) NOT NULL,
myID int NOT NULL IDENTITY (1, 1)
但我想表停止任何插入/更新,其中avaya,startDate和sup_assigned是相同的任何记录或avaya,endDate和sup_assigned在任何记录一样.
我该怎么做才能做到这一点?
我考虑过转换包含startDateinto为hex 的3列的集合,然后添加它们创建Key1列,与包含the endDate和列的其他3列相同Key2.然后设置Key1并Key2作为复合键.
但我得到这个错误:
我应该如何使用MS SQL 2005执行此操作?
我有我认为将是一个简单的演员/转换,但我得到一个奇怪的错误.
这是我的sql:
select CONVERT(datetime,1322510754374,104)
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
Arithmetic overflow error converting expression to data type datetime.
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
select cast(1322510754374 as datetime)
Run Code Online (Sandbox Code Playgroud)
但我得到同样的错误
我想弄明白.还有另一种方法可以将bigint转换为日期时间吗?
我期待今天的日期:2011-11-29 17:26:52.257,但我所展示的int是较早的一天.
因为我需要将它与它进行比较
getDate()
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个Windows服务(C#),我创建多个线程,尝试更新我的数据库中的状态(SQL Server 2005).
我SELECT最初有一个,UPDATE后来必须执行.当我不使用锁来同步我的线程时,我收到错误
已经有一个与此Connection关联的开放DataReader,必须先关闭它
但是当我使用lock(在静态对象上)时,更新速度非常慢.
任何人都可以帮助我解决这个问题.
sql-server-2005 ×10
c# ×6
sql ×5
sql-server ×3
.net ×2
asp.net ×1
between ×1
c#-2.0 ×1
casting ×1
date ×1
encryption ×1
hex ×1
logic ×1
primary-key ×1
t-sql ×1