September 04, 2010, 12:07:02 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Retrieve data from an SQL server.  (Read 1416 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« on: March 28, 2009, 10:07:19 AM »

This is how i retrieve data from an SQL database.


Code
GeSHi (csharp):
  1.  public void getDataFromPersonID(int id)
  2.        {
  3.            string sqlQuery = "select * from table, where Person_ID = " + id;
  4.            SqlCommand cmd = new SqlCommand(sqlQuery, conn);
  5.  
  6.            conn.Open();
  7.            a = new SqlDataAdapter(cmd);
  8.            s = new DataSet();
  9.            a.Fill(s);
  10.            conn.Close();
  11.  
  12.            foreach (DataRow dr in s.Tables[0].Rows)
  13.            {
  14.                this._Persoon_ID = (int)dr["Person_ID"];
  15.                //other columns
  16.            }
  17.        }
  18.  
  19.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
« on: March 28, 2009, 10:07:19 AM »

Your Ad Here
 Logged
jurka
Staff
Member
*
*

Reputation: 5
Offline Offline
Posts: 188
Referrals: 0

Awards
« Reply #1 on: March 29, 2009, 05:47:44 AM »

I would say it's cleaner and easier to understand then it's in Java. Good job!
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« Reply #2 on: March 29, 2009, 07:36:19 AM »

I would say it's cleaner and easier to understand then it's in Java. Good job!


The code above is using ado.net but it can be done much easier using TableAdapters, read this: http://www.engineeringser...ableadapters-t2973.0.html

Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here
Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.341 seconds with 35 queries.

Google visited last this page September 01, 2010, 07:14:06 AM