© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
2 replies
Davaaron

❔ Get an entity with Sql data client

Hi,
Im trying to read some data with the sql data client and Im stuck.
The data looks like this: ID (uniqueidentifer, PK), Forename (nvarchar), Lastname (nvarchar), Birthday (datetime)
The code looks like this
 // Set the connection, command, and then execute the command with query and return the reader.  
        public static SqlOutput<DataTable> ExecuteReader(String connectionString, String commandText,
            CommandType commandType = CommandType.Text, params SqlParameter[] parameters)
        {
            return Execute(cmd =>
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read()) // HERE THE ERROR IS HAPPENING
                    {
                        Console.WriteLine(String.Format("{0}", reader[0]));
                    }
                }
                return new DataTable();
            }, commandType, parameters);

        }


 var result = SqlHelper.ExecuteReader(ConnectionString, input.script, System.Data.CommandType.Text, input.parameters.Select(x => // input.parameters = @[{'E48CC209-4D6A-4594-BD02-AE74DBCF82EA'}]
            {
                var p = new SqlParameter(x.Key, System.Data.SqlDbType.UniqueIdentifier);
                p.Value = Guid.Parse(x.Value);
                return p;
            }).ToArray());
 // Set the connection, command, and then execute the command with query and return the reader.  
        public static SqlOutput<DataTable> ExecuteReader(String connectionString, String commandText,
            CommandType commandType = CommandType.Text, params SqlParameter[] parameters)
        {
            return Execute(cmd =>
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read()) // HERE THE ERROR IS HAPPENING
                    {
                        Console.WriteLine(String.Format("{0}", reader[0]));
                    }
                }
                return new DataTable();
            }, commandType, parameters);

        }


 var result = SqlHelper.ExecuteReader(ConnectionString, input.script, System.Data.CommandType.Text, input.parameters.Select(x => // input.parameters = @[{'E48CC209-4D6A-4594-BD02-AE74DBCF82EA'}]
            {
                var p = new SqlParameter(x.Key, System.Data.SqlDbType.UniqueIdentifier);
                p.Value = Guid.Parse(x.Value);
                return p;
            }).ToArray());


The error message is:
System.Data.SqlClient.SqlException: "Error converting a character in "uniqueidentifer"."
System.Data.SqlClient.SqlException: "Error converting a character in "uniqueidentifer"."

Somebody has an idea what's wrong? That the script for the table
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Minimum need data to create an Entity
C#CC# / help
4y ago
✅ How to get data from entity without includes?
C#CC# / help
4mo ago
❔ Updating an entity/record with 1 query(?) on Entity Framework
C#CC# / help
4y ago
Entity Data Model Wizard
C#CC# / help
4y ago