0

hi I wrote the code below for fetch data from database with ADO.net to show in kendoGrid in My webservice :

var result = new List<Timeline>();
            TimelineDB _TimelineDB = new TimelineDB();
            SPSecurity.RunWithElevatedPrivileges(delegate ()
            {
                _TimelineDB.loadTimeline_bulk(result, currentUserName);
            });

            return result;

the code wrote in DB layer :

public GeneralDAL.OperationStatus loadTimeline_bulk(List<Timeline> ListTimeline_bulk, string id_user)
        {
            GeneralDAL.OperationStatus operationStatus = GeneralDAL.OperationStatus.OperationSuccessful;
            try
            {
                SqlCommand sqlCommand = new SqlCommand(Returnsp_tbl_TimelineLstShow_bulk(id_user));
                sqlCommand.CommandType = CommandType.Text;
                using (SqlConnection connection = new SqlConnection(GeneralDAL.con))
                {
                    sqlCommand.Connection = connection;
                    try
                    {
                        connection.Open();
                        SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                        try
                        {
                            while (sqlDataReader.Read())
                                ListTimeline_bulk.Add(new Timeline()
                                {
                                    ID_Timeline_bulk = sqlDataReader.IsDBNull(sqlDataReader.GetOrdinal(Timeline.Fildes.ID_Timeline_bulk)) ? General.DefaultValues.Numricguid : sqlDataReader.GetGuid(sqlDataReader.GetOrdinal(Timeline.Fildes.ID_Timeline_bulk)),

and many field but when i debugging the exp eroe :

Unable to cast object of type 'System.Int32' to type 'System.String'.

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • 2
    Whch line does the exception occur exactly – Shahid Manzoor Bhat Dec 19 '19 at 08:27
  • 1
    GetGuid(sqlDataReader.GetOrdinal(Timeline.Fildes.ID_Timeline_bulk)) is this where it throws the error ? Have you tried making it a string ? – Clint Dec 19 '19 at 08:28
  • 1
    Does this help you ? [here](https://stackoverflow.com/questions/19582256/unable-to-cast-object-of-type-system-int32-to-type-system-string-in-dataread) – WilliamW Dec 19 '19 at 08:30

0 Answers0