This has had me puzzled for quite some time, and I have not been able to find a clear answer..
Why is it that while using the Query analyzer in SQL Server 2005 express, I am able to submit a hexadecimal value eg:
UPDATE Table_A
SET COLUMN_B = 0xabc123ff (example)
WHERE (COLUMN_A = 'hello')
When I use that in c# it gives me the error "Incorrect syntax near COLUMN_B"
And when I make a stored procedure it still (seems to) work as well, when just opening it through visual studio..
However when I call this stored procedure in visual studio through c# I get the error: "Incorrect syntax near COLUMN_B"
===EXTRA INFO===
COLUMN_B is a varbinary(1740).
I tried receiving the input as a varchar and then converting it, but it doesn't like this either. also converting it does not work..
I have seen some queries out there that seems to do what I want, but they are rather large. How can I ensure that my c# code would handle exactly the same as when entering the data through a query?
Apologies if this seems a bit unclear, I'll provide more code later if required as I do not have it on hand currently..
UPDATE
The bit shown below is what I use for to call my sql stored procedure, this has worked fine with all my other stored procedures so far..
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WebDB"].ConnectionString))
{
//State the Stored Proc and add Values to 'cmd' to pass to the Stored Proc
SqlCommand cmd = new SqlCommand("_USP_inv", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Name", C5_name.Text);
cmd.Parameters.AddWithValue("Inventory", inventory);
try
{
// Open Connection and execute Stored Proc
conn.Open();
cmd.ExecuteScalar();
....
finally
{
if (conn.State == System.Data.ConnectionState.Open)
{
//Close connection IF open
conn.Close();
}
}
}
and the stored procedure as it is now
@Name varchar(10),
@Inventory varbinary(1740)
AS
UPDATE Inventory
SET Inventory = @Inventory
WHERE (Name = @Name)
C#code must be submitting something different to what you are submitting manually. Without seeing the code impossible to say why. But you should be using parameterised queries anyway.