insert into sql table column as GUID

Posted by loviji on Stack Overflow See other posts from Stack Overflow or by loviji
Published on 2010-03-18T13:57:13Z Indexed on 2010/03/18 14:01 UTC
Read the original article Hit count: 467

Filed under:
|
|

I have tried with ado.net create table columnName with unique name. as uniquename I use new Guid()

    Guid sysColumnName = new Guid();
    sysColumnName = Guid.NewGuid();

    string stAddColumn = "ALTER TABLE " + tableName + " ADD " + sysColumnName.ToString() + " " + convertedColumnType + "  NULL";
    SqlCommand cmdAddColumn = new SqlCommand(stAddColumn, con);
    cmdAddColumn.ExecuteNonQuery();
    con.Close();

and it fails:

System.Data.SqlClient.SqlException: Incorrect syntax near '-'. ? System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) ? System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

now question, how can i fix it, or how can use different way to create unique column?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ADO.NET