954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get data from Access instead of Notepad (URGENT)

Hi

I want to get data from Access instead of notepad.
Here are the codes to get data from notepad by entering IC number (equivalent to ID number). The records are stored in 'Folder'.


public void btnGo_Click_1(object sender, System.EventArgs e)// -->User can select the file by entering the IC Nunber in textbox and program will check for file existence and null file
{
enable();
/** [Retrieve IC Number from tboxEnterICNo] **/
strFileName2 = tboxEnterICNo.Text;
path = @"Folder\"+strFileName2+".txt";
/** [Check for file existence] **/
if(File.Exists("Folder\\"+strFileName2+".txt"))// -->If file exists, open DisplayGraph form and display the graph
{
displaygraph.names = path;// -->copies the path to DisplayGraph form
displaygraph.ShowDialog();// -->Opens DisplayGraph form to display graph
}//End of if-condition
else
{
MessageBox.Show("File does not exist! Please create a new profile.", "Invalid File Type", MessageBoxButtons.OK, MessageBoxIcon.Error );
}// -->End of else-condition
}// -->End of btnGo_Clicks module


How should i go about to keep the records in Access and also specify retrieving of the queried data from an Access table instead?

I need some help about what to do and how the codes look like.
Thank you very much!

c#dummie
Light Poster
38 posts since Jul 2005
Reputation Points: 10
Solved Threads: 1
 

a little sample to help you out,
but you'd better read some ADO.Net tutorials

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

//

//  namespaces needed fo data access

//

using System.Data;

using System.Data.OleDb;



namespace msaccess

{

    class Program

    {

        static void Main(string[] args)

        {

            //

            //  Initialization

            //



            string ic_number = "648937693";



            string path = Directory.GetCurrentDirectory();

            path += "\\Folder\\MyDatabase.mdb";



            // Connection object

            var cn = new OleDbConnection(

                "Provider=Microsoft.Jet.OLEDB.4.0;" +

                "Data Source=" + path);



            // sql command object, that will select your data

            var cmd = new OleDbCommand(

                "select MyField1, MyField2 from MyTable where ICNumber = @icnumber", cn);



            // this will insert "648937693" in @icnumber in SQL select statement

            cmd.Parameters.AddWithValue("@icnumber", ic_number);



            // table adapter

            // it can execute sql commands 
            // and fill table objects with data from database

            var adapter = new OleDbDataAdapter(cmd);



            var table = new DataTable();



            // here adapter opens connection

            // retrieves data with select command

            // and stores it in table object

            adapter.Fill(table);



            // iterate through rows of data

            foreach (DataRow row in table.Rows)

            {

                // do your stuff

                string s = string.Format(
                              "MyField1: {0} MyField2: {1}", 
                              row["MyField1"], row["MyField2"]);

                Console.WriteLine(s);

            }



            // wait

            Console.ReadLine();

        }

    }

}


good luck

kamisori
Newbie Poster
5 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

oh ####, this post is 4 years ago)))))
i'm an idiot

kamisori
Newbie Poster
5 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You