Join Dotnetcodes DotnetCodes.com is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login
ASP.net MVC Interview Questions Answers Interview Questions
Get Started Developing for Android Apps with Eclipse Articles
Serial Number in SSRS Articles
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
Whats New in ASP.NET 4.0 Part 2 Articles
How to Print a Crystal Report direct to printer Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
Html5 interview questions and answers Interview Questions
SharePoint 2010 interview Questions Answers Interview Questions
Infosys Interview Questions Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
Populate or bind Dropdownlist in Asp.net using Jquery and Json Articles
ASP.NET MVC Overview Interview Questions
Submit Articles | More Articles..

Import Text File In MS-Access database table

Posted By: renukataria on 12/18/2010 9:01:00 AM | Comments:7 [Forward This]
Plz Provide C# Code for ds Problem: I hv one table in Ms-access Datbase name : sac.mdb Table name : Wavelength Structure of wavelength table: *********************************************** ID wavelength P1_Ref P2_Ref 1 325 0.01234 0.02317 2 326 0.00123 0.07612 - --- ------- ------- - --- ------- ------- 752 1075 0.07654 0.001543 *********************************************** This is the structure of my wavelength table.... From Wavelength 325 to 1075.... and i have text File with structure: ******************************************** wavelength p3_Ref 325 0.00012 326 0.00123 327 0.00134 --- ------- --- ------- 1075 0.00654 ******************************************** Now i need C# Code to Import this text file in to Wavelength table and give Output as follows: ************************************************************ ID wavelength P1_Ref P2_Ref P3_Ref 1 325 0.01234 0.02317 0.00012 2 326 0.00123 0.07612 0.00123 - --- ------- ------- ------ - --- ------- ------- ------ 752 1075 0.07654 0.001543 0.00654 ************************************************************ Plz Help me, Try to solve my Problem as soon as possible... Its Urgent...
Read CommentsComments Category:CSharp Reply to this PostReply

Dear Friends, Dont forget to bookmark and submit your posting to social websites listed above.It will bring more visibility, buzz and fast action to attend your post

Responses to the Discussion: Import Text File In MS-Access database table
Reply by: renukataria on: 1/26/2011 3:40:43 AM
Hello Sir.... how we can plot line graph in windows application of .net with c# using text file as input.... the format of text file is: Wavelength Reflectance 325 0.09989 326 0.090777 -------------------------------- ------------------------------- 1075 0.06866 i have to select text file using OpenfileDialog then it will plot graph on form.. plz help me to solve this problem i need it urgently... thanks in advance.....
Reply by: renukataria on: 12/20/2010 9:25:05 AM
Thanks jaishree..... now i can import my textfile to Access database..... thanku soo much....
Reply by: renukataria on: 12/20/2010 9:21:06 AM
Thanku soo much Mr. rakesh, I had done it... thanku soo much...
Reply by: renukataria on: 12/20/2010 2:06:57 AM
Thanks jaishree, actually i m new to this technology, can u plz provide the code for this problem.... i ll be very thankful to u.....
Reply by: Jaishree on: 12/19/2010 10:27:08 PM
Your easy solution is to do all from within access. Modify your Wavelength table to add the new Field P3_Ref in the table designer or if you must do it from C# the SQL is ALTER TABLE Wavelength ADD COLUMN P3_Ref Double; Import the new data as a new table. File>Get External Data> Import In the Import File dialog: select files of Type: Text Files and choose your text file. Step thought the Import Text Wizard (choose delimited file with space as the delimiter). Click on each field and set the data type. When this is done you will have imported all the data as a new table (WavelengthP3). Then it is simply a matter of updating your Wavelength table with the following query (copy and paste into the query designer). UPDATE Wavelength INNER JOIN WavelengthP3 ON Wavelength.wavelength=WaveLengthP3.wavelength SET Wavelength.P3_Ref = WavelengthP3.P3_Ref; If you must do from C# then use Kamran’s streamreader with the following SQL UPDATE Wavelength SET Wavelength.P3_Ref = Variable1 WHERE (((Wavelength.wavelength)= Variable2));
Reply by: renukataria on: 12/19/2010 7:47:01 AM
Hello Mr. Rakesh, Thanks for ur Help….. but still my problem is there... When I add new plant details in database then I hv to also add new column in table Wavelength with that plant name.(This i had done.) and import new text file in that column. The suggestion that u recommend in that we can only import into the columns that I had declared in the class… public decimal P3_Ref {get; set;} it is just for 1 column only…. Here i write some code in that I am little bit succcessfull but problem is that it Import record after the last record in the database table, I want to add it in series from Wavelength 325 to 1075……… private void button2_Click(object sender, EventArgs e) { string strProvier = "Provider=Microsoft.Jet.OLEDB.4.0; DataSource=|DataDirectory|sac.mdb; Jet OLEDB:Database Password=*1234#"; OleDbConnection con = new OleDbConnection(strProvier); OleDbCommand cmd = new OleDbCommand(); int effectedRow = 0; int lineCounter = 0; con.Open(); if ((con.State.ToString() == "Open")) { StreamReader stReader = new StreamReader(ofd.FileName); //Ofd = Open file Dilaog string[] strRowData = null; while (stReader.Peek() >= 0) { lineCounter = lineCounter + 1; strRowData = stReader.ReadLine().Split( \t ); try { cmd.CommandText = "INSERT INTO Wavelengtha(AcaciaMollissima) VALUES ( " + strRowData[1] + " )"; cmd.Connection = con; if ((effectedRow == -1)) { //Messagebox.Show("Line: " + lineCounter + " Error"); } else { // Messagebox.Show("Line: " + lineCounter + " Executed Successfully"); } } catch (OleDbException er) { MessageBox.Show("Line: " + lineCounter + " Error: " + er.Message); } } stReader.Close(); con.Close(); } else { MessageBox.Show("Not Connected To Database"); } } Output of above Code: ID Wavelength P1 p2 p3 1 325 0.0001 0.0002 2 326 0.1200 0.0021 - --- ------ ------ 751 1075 0.0023 0.0056 752 0.0001 753 0.0765 754 0.0023 --- ------ --- ------ 1502 0.0021 I want Ouput Like: ID Wavelength P1 p2 p3 1 325 0.0001 0.0002 0.0001 2 326 0.1200 0.0021 0.0765 - --- ------ ------ ------- 751 1075 0.0023 0.0056 0.0021 Plz try to solve my Problem.
Reply by: rakesh on: 12/18/2010 12:38:49 PM
Hi, Best thing I will recommend is first make a Class like public class WaveLenthInfo { public int Id {get; set;} public int WaveLength {get; set;} public decimal P1_Ref {get; set;} public decimal P2_Ref {get; set;} public decimal P3_Ref {get; set;} } Then load your table data into a List<WaveLenthInfo> list then loop through each line of your text file and extract the P3_ref data and fill in releated object public Class1() { List<WaveLenthInfo> objList = yourListFromTable; using (StreamReader reader = new StreamReader((buffer), Encoding.ASCII)) { string line = string.Empty; while ((line = reader.ReadLine()) != null) { if (line.Trim().Length > 0) { int irecordId = Convert.ToInt32(line.Substring(0, 2)); objList.Find(h => h.Id == iRecordID).P3_Ref =Decimal.Parse(line.Substring(3, 8)); line = null; obj = null; } } reader.Close(); reader.Dispose(); } } public class WaveLenthInfo { public int Id { get; set; } public int WaveLength { get; set; } public decimal P1_Ref { get; set; } public decimal P2_Ref { get; set; } public decimal P3_Ref { get; set; } }
 
You have not Logged In,  click here to Login
Reply Here
 
, I agree the terms and conditions of this website
  
  .NET Framework
  ADO.NET
  AJAX
  Android
  ASP.NET
  ASP.NET AJAX
  ASP.NET MVC
  Azure
  Best Practices
  BizTalk Server
  C++
  CSharp
  CSS
  DBMS
  Error and Resolution
  HTML
  IIS
  JAVA
  JavaScript
  JQwery
  JSP
  LINQ
  Management
  Mobile
  ODP.NET
  OOPS
  Oracle
  Others
  Pattern and Practices
  PHP
  SAP
  SEO
  SharePoint
  Silverlight
  Sql Server
  SSAS
  SSIS
  SSRS
  Survey
  UML
  UNIX
  VB
  VB.NET
  VS 2010
  WCF
  Web Analytics
  Windows Forms
  WPF
  WWF
  XML
  XSLT
  .NET Framework
  ADO.NET
  AJAX
  Android
  ASP.NET
  ASP.NET AJAX
  ASP.NET MVC
  Azure
  Best Practices
  BizTalk Server
  C++
  CSharp
  CSS
  DBMS
  Error and Resolution
  HTML
  IIS
  JAVA
  JavaScript
  JQwery
  JSP
  LINQ
  Management
  Mobile
  ODP.NET
  OOPS
  Oracle
  Others
  Pattern and Practices
  PHP
  SAP
  SEO
  SharePoint
  Silverlight
  Sql Server
  SSAS
  SSIS
  SSRS
  Survey
  UML
  UNIX
  VB
  VB.NET
  VS 2010
  WCF
  Web Analytics
  Windows Forms
  WPF
  WWF
  XML
  XSLT
All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher