loading data from database to C#?

guys.. im trying to load data from access to the labels in C#..

but im having difficulty in doing that..

tnx for the urgent reply..

Update:

here are my codes..

da = new OleDbDataAdapter("Select * from partylist1",conn);

ds = new DataSet();

da.Fill(ds);

dataGridView1.DataSource = ds.Tables[0].DefaultView;

DataView dv = (DataView)dataGridView1.DataSource;

if (dv.Count > 0)

{

rbtnParty1.Text = dv[0]["partyname1"].ToString();

rbtnPres1.Text = dv[0]["president1"].ToString();

rbtnVice1.Text = dv[0]["vicepresident1"].ToString();

}

but it cant find the table where i stored the data

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    You need to look at your definition of your conn object. That's your connection object. It needs to point to the database (drive, path and filename)

  • Anonymous
    1 decade ago

    Use OleDbCommand to load data from Access database mdb

    using System;

    using System.Data;

    using System.Data.OleDb;

    class MainClass

    {

    [STAThread]

    static void Main(string[] args)

    {

    string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Northwind.mdb";

    string SQL = "SELECT * FROM Orders";

    OleDbConnection conn = new OleDbConnection(ConnectionString);

    OleDbCommand cmd = new OleDbCommand(SQL);

    cmd.Connection = conn;

    conn.Open();

    OleDbDataReader reader = cmd.ExecuteReader();

    while (reader.Read())

    {

    Console.Write("OrderID:"+reader.GetInt32(0).ToString() );

    Console.Write(" ,");

    Console.WriteLine("Customer:" + reader.GetString(1).ToString() );

    }

    reader.Close();

    conn.Close();

    }

    }

    The Output May Look Somewhat Like This

    OrderID:10330 ,Customer:LILAS

    OrderID:10331 ,Customer:BONAP

    OrderID:10332 ,Customer:MEREP

    OrderID:10333 ,Customer:WARTH

    OrderID:10334 ,Customer:VICTE

    ...

    ...

    For more information please checkout this url

    http://www.java2s.com/Tutorial/CSharp/0560__ADO.Ne...

Still have questions? Get your answers by asking now.