所以我有这个表格列AgentsView (varbinary(max), null)
我正在尝试使用新的二进制文件更新该列,但我一直收到此错误[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Implicit conversion from data type nvarchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.
我已经尝试了很多东西来绕过这个障碍。以下是一些生成相同错误消息的尝试
update [dbo].[Agents] set [AgentsView] = 0x1EFBBBF3C587472615365726
update [dbo].[Agents] set [AgentsView] = '0x1EFBBBF3C587472615365726'
update [dbo].[Agents] set [AgentsView] = '1EFBBBF3C587472615365726'
update [dbo].[Agents] set [AgentsView] = Cast('1EFBBBF3C587472615365726' as varbinary(max))
update [dbo].[Agents] set [AgentsView] = Convert(varbinary(max), '1EFBBBF3C587472615365726')
update [dbo].[Agents] set [AgentsView] = Convert(varbinary(max), 0x1EFBBBF3C587472615365726)
update [dbo].[Agents] set [AgentsView] = Convert(varbinary(max), '0x1EFBBBF3C587472615365726')
我正在使用PHP,并且还试图像这样投射变量
$newData = (binary) . "1EFBBBF3C587472615365726"
但是我无法理解为什么我仍然像以前一样得到同样的信息。
有什么建议吗?
此致
答案 0 :(得分:0)
我试过这个:
创建表格:
CREATE TABLE [dbo].[Agents](
[id] [int] NULL,
[AgentsView] [varbinary](max) NULL
)
然后运行:
INSERT INTO [dbo].[Agents] VALUES
(1, NULL)
然后从PHP页面更新:
<?php
header('Content-Type: text/html; charset=utf-8');
$serverName = "SERVER\TEST";
$connectionInfo = array("Database"=>"Test");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
$tsql1 = "UPDATE [dbo].[Agents] SET [AgentsView] = 0x1EFBBBF3C587472615365726 WHERE id = 1";
$stmt1 = sqlsrv_query( $conn, $tsql1);
if( $stmt1 === false ) {
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_free_stmt( $stmt1);
sqlsrv_close( $conn );
我在Agents
表中没有错误:
id AgentsView
1 0x1EFBBBF3C587472615365726
那么,你如何得到你想要写入你的表的这个值?你能展示你的PHP代码吗?