Sql 显示最新更新的数据
我必须在文本文件中显示当前正在更新的数据。问题是,我对需要显示的列使用了Sql 显示最新更新的数据,sql,sql-server,Sql,Sql Server,我必须在文本文件中显示当前正在更新的数据。问题是,我对需要显示的列使用了CONVERT函数。显示的数据是System.Byte[]。我需要显示的实际数据是varbinary字符串 -- This query is displaying the data before updating the status. query = SELECT CONVERT(varchar(10), Start_RG, 2) AS Start_RG, CONVERT(varchar(10), End_RG, 2) A
CONVERT
函数。显示的数据是System.Byte[]
。我需要显示的实际数据是varbinary
字符串
-- This query is displaying the data before updating the status.
query = SELECT CONVERT(varchar(10), Start_RG, 2) AS Start_RG, CONVERT(varchar(10), End_RG, 2) AS End_RG, Status FROM RG WHERE Status = 'New';
command = new SqlCommand(query, cnn);
dR = command.ExecuteReader();
if (dR.HasRows)
{
dR.Close();
-- This is the query for updating the status to 'In Use'. I'm using the OUTPUT clause to display the data that has been update.
sql = UPDATE TOP (1) RG SET Status = 'In Use' OUTPUT deleted.Start_RG, deleted.End_RG, deleted.Status WHERE Status = 'New';
cmd= new SqlCommand(sql, cnn);
dataReader = cmd.ExecuteReader();
using (StreamWriter tw = File.AppendText(Path))
{
while (dataReader.Read())
{
tw.WriteLine("assign..\n");
tw.WriteLine("Start RG: {0}", Convert.Tostring((byte[])dataReader["Start_RG"]));
tw.WriteLine("End RG: {0}", Convert.Tostring((byte[])dataReader["End_RG"]));
}
}
}
如何获取当前将状态更新为“正在使用”的
Start\u RG
和End\u RG
?我可以使用任何其他建议来代替OUTPUT
子句吗?无论您使用OUTPUT子句做什么都可以。要将字节[]读取为字符串,可以使用以下方法。杠杆式堆栈溢出回答:
tw.WriteLine(“Start RG:{0}”,Encoding.ASCII.GetString(((字节[])dataReader[“Start_RG”]);//根据编码,您需要选择适当的静态方法
WriteLine(“End RG:{0}”,Encoding.ASCII.GetString(((byte[])dataReader[“End_RG”]);
我已经更新了C#代码在关键字“CONVERT”附近有一个错误语法不正确
好的,所以只要用C#转换它,首先你必须在调用writeline
lol之前将它完全转换为字符串。或者至少把你的字符串转换代码放在writeline
调用中。对不起,我把代码放错地方了这个问题。在编码中,我将代码放在writeline之前。显示的数据仍然是System.Byte[]。