Get data from Access instead of Notepad (URGENT)

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Jul 2005
Posts: 38
Reputation: c#dummie is an unknown quantity at this point 
Solved Threads: 1
c#dummie c#dummie is offline Offline
Light Poster

Get data from Access instead of Notepad (URGENT)

 
0
  #1
Sep 13th, 2005
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!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: kamisori is an unknown quantity at this point 
Solved Threads: 1
kamisori kamisori is offline Offline
Newbie Poster

Re: Get data from Access instead of Notepad (URGENT)

 
0
  #2
Feb 20th, 2009
a little sample to help you out,
but you'd better read some ADO.Net tutorials

  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Linq;
  6.  
  7. using System.Text;
  8.  
  9. using System.IO;
  10.  
  11. //
  12.  
  13. // namespaces needed fo data access
  14.  
  15. //
  16.  
  17. using System.Data;
  18.  
  19. using System.Data.OleDb;
  20.  
  21.  
  22.  
  23. namespace msaccess
  24.  
  25. {
  26.  
  27. class Program
  28.  
  29. {
  30.  
  31. static void Main(string[] args)
  32.  
  33. {
  34.  
  35. //
  36.  
  37. // Initialization
  38.  
  39. //
  40.  
  41.  
  42.  
  43. string ic_number = "648937693";
  44.  
  45.  
  46.  
  47. string path = Directory.GetCurrentDirectory();
  48.  
  49. path += "\\Folder\\MyDatabase.mdb";
  50.  
  51.  
  52.  
  53. // Connection object
  54.  
  55. var cn = new OleDbConnection(
  56.  
  57. "Provider=Microsoft.Jet.OLEDB.4.0;" +
  58.  
  59. "Data Source=" + path);
  60.  
  61.  
  62.  
  63. // sql command object, that will select your data
  64.  
  65. var cmd = new OleDbCommand(
  66.  
  67. "select MyField1, MyField2 from MyTable where ICNumber = @icnumber", cn);
  68.  
  69.  
  70.  
  71. // this will insert "648937693" in @icnumber in SQL select statement
  72.  
  73. cmd.Parameters.AddWithValue("@icnumber", ic_number);
  74.  
  75.  
  76.  
  77. // table adapter
  78.  
  79. // it can execute sql commands
  80. // and fill table objects with data from database
  81.  
  82. var adapter = new OleDbDataAdapter(cmd);
  83.  
  84.  
  85.  
  86. var table = new DataTable();
  87.  
  88.  
  89.  
  90. // here adapter opens connection
  91.  
  92. // retrieves data with select command
  93.  
  94. // and stores it in table object
  95.  
  96. adapter.Fill(table);
  97.  
  98.  
  99.  
  100. // iterate through rows of data
  101.  
  102. foreach (DataRow row in table.Rows)
  103.  
  104. {
  105.  
  106. // do your stuff
  107.  
  108. string s = string.Format(
  109. "MyField1: {0} MyField2: {1}",
  110. row["MyField1"], row["MyField2"]);
  111.  
  112. Console.WriteLine(s);
  113.  
  114. }
  115.  
  116.  
  117.  
  118. // wait
  119.  
  120. Console.ReadLine();
  121.  
  122. }
  123.  
  124. }
  125.  
  126. }

good luck
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: kamisori is an unknown quantity at this point 
Solved Threads: 1
kamisori kamisori is offline Offline
Newbie Poster

Re: Get data from Access instead of Notepad (URGENT)

 
0
  #3
Feb 20th, 2009
oh ****, this post is 4 years ago)))))
i'm an idiot
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC