Problem with typical conversions


I'm having trouble dealing with type conversions...


public static string isLocalIncidentSubmitted()

    string query = "SELECT Submit From [MVCOmar].[dbo].PrideMVCSubmitLog WHERE [email protected]";

    DataTable dt = new DataTable();
    SqlConnection connection = new SqlConnection(connectionStr4);

    SqlCommand command = new SqlCommand(query, connection);
    command.Parameters.AddWithValue("@existingNum", MyGlobals1.secondversionDisplayTesting);

    SqlDataAdapter adp = new SqlDataAdapter(command);

        return dt.Rows[0]["Submit"].ToString();   


the table submit is of type varchar

I get a large error but here are first few lines of it:

System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.HasMoreRows()

It looks like your ReportID is a Guid or uniqueidentifier in SQL, but you are trying to give it a string value. Are you sure you're using the correct field in that query?

If your MyGlobals1.secondversionDisplayTesting is a string then do it like:

Guid g = Guid.Parse(MyGlobals1.secondversionDisplayTesting);
command.Parameters.AddWithValue("@existingNum", g);