| | |
Get data from Access instead of Notepad (URGENT)
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Jul 2005
Posts: 38
Reputation:
Solved Threads: 1
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!
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!
•
•
Join Date: Feb 2009
Posts: 5
Reputation:
Solved Threads: 1
a little sample to help you out,
but you'd better read some ADO.Net tutorials
good luck
but you'd better read some ADO.Net tutorials
c# Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- How to assure data gets stored in MS Access (Visual Basic 4 / 5 / 6)
- time to time data updates,to access that data time to time (MySQL)
- retrive data from different tables of Ms access (ASP)
- Archive MSaccess data into a different Access DB (Visual Basic 4 / 5 / 6)
- retrive data from different tables of Ms access (ASP)
- I have error in connection codefor coonect toMS access with OLEDB data source (VB.NET)
- Data From C++ GUI to Excel/Notepad, Application Trouble (C++)
- Sequential Access Data Files (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: Dynamic Form Letters
- Next Thread: Connect to access database on a shared folder
| Thread Tools | Search this Thread |
.net access algorithm alignment app application array bitmap box c# c#gridviewcolumn check checkbox client color combo combobox communication concurrency control conversion csharp custom data database datagrid datagridview dataset datatable datetime degrees draganddrop drawing enabled encryption enum excel file focus form format forms function gdi+ getoutlookcontactusinfcsvfile globalization hospitalmanagementsystem image input install java list localization mandelbroth math messagebox microsoftc#visualexpress mono mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox save server sleep socket sql sql-server statistics string stringformatting sun table text textbox thread time timer update usercontrol validate validation visualstudio webbrowser winforms wpf xml





