I\'m new to SQL Server
I\'ve created my table like this:
CREATE TABLE Accidents (
Id INT NOT NULL PRIMARY KEY IDENTITY,
GUID VARCHAR(100),
I'm guessing your GUID value starts with an a
. If it started with a 3
you'd probably get something more entertaining.
Since you're passing it in as a string, and not escaping it with quotes, you receive an error.
SqlCommand cmd = new SqlCommand("INSERT INTO Accidents (GUID,Latitude,Longitude,PhotoName) VALUES ("
+ "\"" + GUID + "\"," + latitude + "," + longitude + ",\"" + photoName + "\")", con);
A few points:
You should really avoid building queries in this way. Use a stored procedure or parameterized query.
why are you storing a guid
as a varchar()
? There is a very nice Guid
datatype available.
Don't name columns after data types.