C# Reserved Words

Ever wondered what all the reserved words are in C#….well I did. Head on over to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfcsharpkeywords_pg.asp to find out. I’ve copied them below.

abstract event new struct
as explicit null switch
base extern object this
bool false operator throw
break finally out true
byte fixed override try
case float params typeof
catch for private uint
char foreach protected ulong
checked goto public unchecked
class if readonly unsafe
const implicit ref ushort
continue in return using
decimal int sbyte virtual
default interface sealed volatile
delegate internal short void
do is sizeof while
double lock stackalloc
else long static
enum namespace string
Read more

Asp.net Agony

Ever seen this before:
Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.


Well 7 hours later after reading and debugging and then reading and debugging some more I finally found a solution. What I was trying to do was something like this


Sub addData(sender As Object, e As EventArgs)
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim objRdr As OleDbDataReader

objConn = new OleDbConnection(“xxxx”)

objCmd = new OleDbCommand(“INSERT INTO MyTable(Name, Email, Password)VALUES (@Name, @Email, @Password);”,objConn)

’add all our parameters
objCmd.Parameters.Add(“@Name”, “UserID”)
objCmd.Parameters.Add(“@Email”, “no@no.com”)
objCmd.Parameters.Add(“@Password”, “hardpassword”)

Dim blnReturn as Boolean = objCmd.ExecuteNonQuery()

If blnReturn THen
lblError.Text = “Success”
End If
End Sub


The database being used was Microsoft Access 2003. The insert statement would run perfectly in Access but via ADO.net..nope…Invalid Synatax! As it turns out all the different implementations of SQL have a different set of reserved words, password being one of them. Simply placing [] around the value in question fixes the problem. So what are all these reserved words?


http://office.microsoft.com/en-au/assistance/HP010322491033.aspx – for Access 2003
http://office.microsoft.com/en-au/assistance/HP010322481033.aspx – Access Data Types
http://doc.ddart.net/mssql/sql70/ra-rz_8.htm –  SQL Server / MSDE

Read more