web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

get crm data from c# datareader

(0) ShareShare
ReportReport
Posted on by 2,510

Hi, I am trying to connect with the CRM database through c# console application, and I am using data reader to get the result, but I got the format error "Input string was not in a correct format",

 
sql = "select top 10 name from accountbase";
try
                {
                    connection.Open();
                    command = new SqlCommand(sql, connection);
                    dataReader = command.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            Console.WriteLine(String.Format("{ 0}", dataReader[0]));
                        }
                    }
                    dataReader.Close();
                    command.Dispose();
                    connection.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    While using datareader you need to use further methods to access different datatype columns, please check :docs.microsoft.com/.../retrieving-data-using-a-datareader

    Also access CRM db directly is not supported , you should use CRM SDK to access crm entity data, Download CRM SDK you will get sample code for how to retrieve data from CRM using retrieve or retrieve multiple.

    msdn.microsoft.com/.../gg328198.aspx

  • sdnd2000 Profile Picture
    2,510 on at

    I switched to data adapter, then it worked

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    That's fine but keep in mind not to use this way, instead use CRM SDK method to access data which enforce your security permission to get data for you, so you won't get data which you are not supposed to get.

  • Eswar.gadam Profile Picture
    5 on at

    Hi,

    can you please give complete code i am also trying to push data to sql server from dynamics 365. I don't have much knowledge on .net.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans