Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Retrieve data from an SQL server.  (Read 1327 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
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
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: 2593
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
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here