6 Replies - 808 Views - Last Post: 01 May 2013 - 04:35 AM Rate Topic: -----

#1 masterofbonk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-April 13

Nearly impossible: Get a single data row from a database

Posted 30 April 2013 - 07:40 AM

It really blows my mind how there is literally NOTHING on the entire internet explaining how to get 1 datarow from a database in C#. I just spent the last 2 hours researching this and only came up with convoluted and lengthy ways to do this.

I want to get a single data row from my SQL database, based upon a supplied unique identifier (ID number), and the row should be returned as a DataRow object.

Why has no one ever posted about this on the internet?

Is This A Good Question/Topic? 0
  • +

Replies To: Nearly impossible: Get a single data row from a database

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8390
  • View blog
  • Posts: 31,200
  • Joined: 12-June 08

Re: Nearly impossible: Get a single data row from a database

Posted 30 April 2013 - 07:44 AM

What's the difficulty? We have oodles of tutorials on C# and database interactions, MSDN has buckets full of help docs, and these forums are plastered with folks who are using CRUD (Create, Retrieve, Update, Delete) apps.

Ultimately - you are way, way wrong on there being nothing about the topic. ;)
Was This Post Helpful? 0
  • +
  • -

#3 masterofbonk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-April 13

Re: Nearly impossible: Get a single data row from a database

Posted 30 April 2013 - 07:51 AM

View Postmodi123_1, on 30 April 2013 - 07:44 AM, said:

What's the difficulty? We have oodles of tutorials on C# and database interactions, MSDN has buckets full of help docs, and these forums are plastered with folks who are using CRUD (Create, Retrieve, Update, Delete) apps.

Ultimately - you are way, way wrong on there being nothing about the topic. ;)/>


Sorry if I sound ridiculous, but I am BEYOND frustrated right now at how difficult it is to do such a simple thing as having a method return a DataRow object from a SQL database. Also keep in mind I'm pretty new to C# and coming from C++ without much experience with databases.

Please, just give me some kind of link or explanation as to how I can have a method return a DataRow object from a SQL database.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8390
  • View blog
  • Posts: 31,200
  • Joined: 12-June 08

Re: Nearly impossible: Get a single data row from a database

Posted 30 April 2013 - 07:53 AM

.. as I said - read the tutorials.

Just off the first page of the C# tutorials..
http://www.dreaminco...basics-in-c%23/
http://www.dreaminco...lite-with-c%23/
http://www.dreaminco...ng-sql-compact/
http://www.dreaminco...ery-a-database/
Was This Post Helpful? 1
  • +
  • -

#5 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5315
  • View blog
  • Posts: 11,371
  • Joined: 02-June 10

Re: Nearly impossible: Get a single data row from a database

Posted 30 April 2013 - 08:32 AM

Databases: FAQ 31


tlhIn`toq's FAQ list


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Apr 2013
Spoiler



Was This Post Helpful? 0
  • +
  • -

#6 Ghandi_Of_Codez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-March 13

Re: Nearly impossible: Get a single data row from a database

Posted 30 April 2013 - 07:56 PM

cn.Open();
            String cmdString = "Select ColumnName FROM tableName WHERE ID = 'value'";
            SqlCommand cmd2 = new SqlCommand(cmdString, cn);

Was This Post Helpful? 0
  • +
  • -

#7 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5643
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: Nearly impossible: Get a single data row from a database

Posted 01 May 2013 - 04:35 AM

A bare DataRow is not all that helpful without the context of it's DataTable...

Can you load a DataTable with the data? That is, a single row? Now, can't you just pass that single row back?

e.g.
da.Fill(dt);
return (dt.Rows.Count==0) ? null : dt.Rows[0];


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1