Skip to content
Advertisement

Tag: asp.net

NVarChar to C# Data Types

The database stores nvarchar, I retrieve the information and I’d like to jam it into C# data types without any declarative conversion code. Can you implicitly convert nvarchar to C# data types? (e.g. nvarchar to int) Answer Nvarchar is a string, if you want to turn it in to a int you will have to go through some kind of

Sql Command Not Working

I wrote the following code, but nothing is being inserted into the database. I tried changing the SA password in the connection string to something incorrect and the code isn’t catching the exception. What am I doing wrong? Answer As stated by the OP in the comments. Once the try-catch was resolved it was discovered that it just a mismatched

Insert datetime from C# into SQL Server database

when I try to insert datetime value into a SQL Server database I get this error: Conversion failed when converting date and/or time from character string Code: Table table has 1 datetime column called time. Edit: my table created in msSQL 2012: http://i.imgur.com/TJ3t3y7.png my real code is: Answer The actual problem here is that you’re writing the parameter inside quotes:

Calling Functions in SqlCommand

Can I use Sql Server functions in myCommand.CommandText and why? Answer If you mean, SQL Server user defined functions. Then, yes; you can use it normally like: The reason it works is because this is the way that functions are called in SQL Server directly.

Advertisement